How to convert current date to epoch timestamp?

前端 未结 9 2289
情话喂你
情话喂你 2020-12-14 05:41

How to convert current date to epoch timestamp ?

Format current date:

29.08.2011 11:05:02
相关标签:
9条回答
  • 2020-12-14 06:07

    Short-hand to convert python date/datetime to Epoch (without microseconds)

    int(current_date.strftime("%s")) # 2020-01-14  ---> 1578956400
    int(current_datetime.strftime("%s")) # 2020-01-14 16:59:30.251176 -----> 1579017570
    
    0 讨论(0)
  • 2020-12-14 06:13

    Assuming you are using a 24 hour time format:

    import time;
    t = time.mktime(time.strptime("29.08.2011 11:05:02", "%d.%m.%Y %H:%M:%S"));
    
    0 讨论(0)
  • 2020-12-14 06:13
    import time
    def expires():
        '''return a UNIX style timestamp representing 5 minutes from now'''
        return int(time.time()+300)
    
    0 讨论(0)
提交回复
热议问题