Linked Questions

1 vote
2 answers
3k views

I have time since epoch and I am converting it to datetime. import datetime s = '1346114717' t = datetime.datetime.fromtimestamp(float(s)) is this correct? t is in which timezone? How can I convert ...
Alok's user avatar
  • 45
1 vote
1 answer
2k views

Using Python, I have a datetime object with the value (for example) datetime(2021, 12, 28, 22, 31, tzinfo=tzutc()) This prints as 2021-12-28 22:31:00+00:00 How do I display that in US/Pacific? I've ...
shepster's user avatar
  • 569
443 votes
26 answers
874k views

How do I convert a datetime string in local time to a string in UTC time? I'm sure I've done this before, but can't find it and SO will hopefully help me (and others) do that in future. ...
Tom's user avatar
  • 44.9k
331 votes
16 answers
666k views

I've never had to convert time to and from UTC. Recently had a request to have my app be timezone aware, and I've been running myself in circles. Lots of information on converting local time to UTC, ...
MattoTodd's user avatar
  • 15.3k
393 votes
12 answers
844k views

I am dealing with dates in Python and I need to convert them to UTC timestamps to be used inside Javascript. The following code does not work: >>> d = datetime.date(2011,01,01) >>> ...
user avatar
321 votes
13 answers
691k views

I have a bunch of datetime objects and I want to calculate the number of seconds since a fixed time in the past for each one (for example since January 1, 1970). import datetime t = datetime.datetime(...
Nathan Lippi's user avatar
  • 5,277
320 votes
12 answers
726k views

I have dt = datetime(2013,9,1,11), and I would like to get a Unix timestamp of this datetime object. When I do (dt - datetime(1970,1,1)).total_seconds() I got the timestamp 1378033200. When ...
kun's user avatar
  • 4,327
162 votes
20 answers
254k views

I want to compare UTC timestamps from a log file with local timestamps. When creating the local datetime object, I use something like: >>> local_time=datetime.datetime(2010, 4, 27, 12, 0, 0, ...
Adam Matan's user avatar
  • 138k
152 votes
10 answers
317k views

How do I convert a time to another timezone in Python?
Trying_hard's user avatar
  • 9,631
77 votes
10 answers
74k views

In Python, how do you find what UTC time offset the computer is set to?
Paul's user avatar
  • 4,480
84 votes
6 answers
114k views

We can use time.tzname get a local timezone name, but that name is not compatible with pytz.timezone. In fact, the name returned by time.tzname is ambiguous. This method returns ('CST', 'CST') in my ...
user805627's user avatar
  • 4,487
64 votes
6 answers
90k views

How do you convert a timezone-aware datetime object to the equivalent non-timezone-aware datetime for the local timezone? My particular application uses Django (although, this is in reality a generic ...
kes's user avatar
  • 6,277
70 votes
7 answers
217k views

Let's say I have a variable t that's set to this: datetime.datetime(2009, 7, 10, 18, 44, 59, 193982, tzinfo=<UTC>) If I say str(t), i get: '2009-07-10 18:44:59.193982+00:00' How can I get a ...
mike's user avatar
  • 49.8k
71 votes
6 answers
102k views

I have a datetime in utc time zone, for example: utc_time = datetime.datetime.utcnow() And a pytz timezone object: tz = timezone('America/St_Johns') What is the proper way to convert utc_time to the ...
Tzach's user avatar
  • 13.4k
54 votes
11 answers
13k views

How do I get the Olson timezone name (such as Australia/Sydney) corresponding to the value given by C's localtime call? This is the value overridden via TZ, by symlinking /etc/localtime, or setting a ...
Matt Joiner's user avatar

15 30 50 per page