简体   繁体   中英

Converting a javascript .millis() object into its python equivalent

I have the following functional code in javascript:

Date(0).update(2020,1,1,12,0,0).millis()

I have been trying to get it working in python. But I must be doing something very wrong.

import time
time_tuple = time.strptime('2020-1-1 12:00:00', '%Y-%m-%d %H:%M:%S')
time_epoch = time.mktime(time_tuple)

You can do something like this:

dt_obj = datetime.strptime('2020-1-1 12:00:00',
                           '%d.%m.%Y %H:%M:%S')
millisec = dt_obj.timestamp() * 1000

Here is the explanation of the format specifiers from the official documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM