Miklas Njor

Correcting Epoch time strangeness

Skærmbillede 2016 03 11 kl. 09.43.00

Skærmbillede 2016 03 11 kl. 09.43.00

I was accessing data from an and made an Exploratory (EDA). One irregularity that I noticed, was that the epoch time was off by roughly forty-six thousand years! How the epoch came to be so long, could stem from the decimal “dot” had somehow been removed.A hack -around was to convert the epoch time to a string variable, chop off the last three digits, insert a decimal dot, and glue the string back together as an float. This way I was able to get the correct value. As as I can see, this way of doing it, is safe for values up to the year 9999, possibly more.

__author__ = 'Miklas Njor - iAmGoldenboy - https://miklasnjor.com'__datum__ = '10/03/16'import timeoriginalEpoch = 1455624188738def correctingEpoch(epochTimeInt): insertDecimal = "{}.{}".format( str(originalEpoch)[:10], str(originalEpoch)[10:]) return float(insertDecimal)# Testing# The original epoch stringprint("Epoch Original: ", originalEpoch)# Which is off by 46.000 years!print("Epoch Converted: ", time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime( originalEpoch) ) )# proving that it must be the decimal that was removedprint("Epoch w. decimal: ", time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime( 1455624188.738 ) ))# Using the function correctingEpoch to get the correct time.print("Epoch Corrected: ", time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime( correctingEpoch(originalEpoch) ) ))
Exit mobile version