Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7699733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:32:52+00:00 2026-05-31T22:32:52+00:00

I am using datetime.fromtimestamp to convert epoch time into local time. I found that

  • 0

I am using datetime.fromtimestamp to convert epoch time into local time. I found that datetime.fromtimestamp does a discrete jump of one hour at a certain point of time and I am completely baffled as to why it does that.

(I am also using time.mktime to convert a datetime object into epoch time, as suggested by Raymond Hettinger. I’m not sure whether this is relevant information for this question, so I’m saying this just in case.)

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time, datetime
>>> def datetime_to_epoch_time(datetime_):
...     return time.mktime(datetime_.timetuple()) + datetime_.microsecond / 1e6
... 

Picking a specific epoch time:

>>> x = datetime_to_epoch_time(datetime.datetime(2012, 3, 30, 3, 0))

Converting it to a datetime using fromtimestamp:

>>> datetime.datetime.fromtimestamp(x)
datetime.datetime(2012, 3, 30, 3, 0)

We get a time of 3am.

Now let’s convert the time that’s exactly one second before it:

>>> datetime.datetime.fromtimestamp(x-1)
datetime.datetime(2012, 3, 30, 1, 59, 59) 

We suddenly get 1:59am!

What happened? I know that stuff like that happens around leap days, but since when is March 30th a leap day?

I should note that I’ve had this happen to me only on Linux and not on Windows. And I think that different Linux computers (in different timezones) have a different time point in which fromtimestamp does the jump.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:32:54+00:00Added an answer on May 31, 2026 at 10:32 pm

    Easy. March 30th is presumably a daylight savings time switch in your timezone.

    So on that day, time did indeed go from 1:59:59 to 3:00:00

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using DateTime.ToLocalTime() to convert dates from UTC to local time. My time
I am using: datetime.now() to get the current time in an Event app that
I have an datetime object that I want to remove one hour to display
Using Python, I'm storing a date & time as datetime.datetime into GAE. Is there
I get time data '19/Apr/2011:22:12:39' does not match format '%d/%b/%y:%H:%M:%S' when using datetime.strptime('19/Apr/2011:22:12:39','%d/%b/%y:%H:%M:%S') What
I'm trying to parse a date/time string using DateTime.ParseExact . It works everywhere, except
I'm using a DateTime in C# to display times. What date portion does everyone
I have a page that is currently using the datetime microformat to display a
I'm running into an odd bug using datetime fields in SQL Server 2005. The
How can I save a Properties.Settings.Default.Array using DateTime format (with just the time)?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.