2

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?

Community
  • 1
  • 1
user3242205
  • 89
  • 1
  • 6

1 Answers1

2

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()
Community
  • 1
  • 1
Andrew Clark
  • 202,379
  • 35
  • 273
  • 306