I have "Fri Dec 04 07:00:16 CST 2020" timestamp, need to convert it to Unix/Epoch time in python code And how to convert reverse [Epoch time to above format]
Thanks,
I have "Fri Dec 04 07:00:16 CST 2020" timestamp, need to convert it to Unix/Epoch time in python code And how to convert reverse [Epoch time to above format]
Thanks,
You can use dateparser dateparser . Here is the code
>>> import dateparser
>>> dateparser.parse('Fri Dec 04 07:00:16 CST 2020').strftime('%s')
'1607045416'
you have to install dateparser first
For reverse format you can do the same by passing argument to strftime.strftime
You can use time
and datetime
module:
>>> import time
>>> import datetime
>>> now = time.time()
>>> now
1607055249.4696143
>>> datetime.datetime.fromtimestamp(now).strftime('%Y-%m-%d %H:%M:%S')
'2020-12-04 01:14:09'
If you want to modify the format, you can take a look to the strftime documentation here.