# Correcting Epoch time strangeness

I was accessing data from an API and made an Exploratory Data Analysis (EDA). One irregularity that I noticed, was that the epoch time was off by roughly forty-six thousand years! How the epoch time came to be so long, could stem from the decimal “dot” had somehow been removed.A hack work-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 far 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) ) ))`
Læs også  How to add collapsible comment form to your wordpress blog