import time


def timestamp_in_ms(dt=None, dtype=int):
    """Convert given datetime into UNIX timestamp.

    If dt is None, current time will be used.
    dtype is the datatype returned (int or float).
    """
    if dt is None:
        in_ms = time.time()*1e3
    else:
        in_ms = time.mktime(dt.timetuple())*1e3
    return dtype(in_ms)