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?

0

1 Answer 1

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() 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.