Search code examples
python-2.7datetimedateparser

how to convert a datetime format to a millisec in python 2?


so python2 does not have datetime.timestamp() is there any way to convert a simple datetime format to epoch like format in other words in milliseconds , or is there any other way to convert the start_date to milliseconds format

from datetime import datetime
import dateparser 

time_interval = "1h"

start_date = dateparser.parse(time.interval)

print (str(start_date))

date_in_millisec = start_date.timestamp() 

Solution

  • from datetime import datetime
    import dateparser 
    
    time_interval = "1h"
    
    start_date = dateparser.parse(time.interval)
    
    print (str(start_date))
    
    date_in_millisec_compared_to_now = datetime.now() - start_date
    
    print (str(date_in_millisec_compared_to_now))