Reputation: 89
I'm attempting to convert time.time()
to the local time. Reading python datetime to unix timestamp, I understand there's some limitations given that the timestamp is in UTC. However, in lieu of just doing:
time.time() - (6*60*60)
Is there a way to convert from UTC to CST and get the CST Unix timestamp?
Upvotes: 2
Views: 1251
Reputation: 208395
You can use the datetime module to get the current local time, and then convert that to a UNIX timestamp:
import datetime
import calendar
now = calendar.timegm(datetime.datetime.now().timetuple())
Or on Python 3.3+:
import datetime
now = datetime.datetime.now().timestamp()
Upvotes: 2