However, as the definition of Unix Epoch Time explicitly excludes leap seconds, you can safely ignore this and simply recalculate seconds from the current UTC time. You would have to track the number of seconds to add at each time since leap seconds are not announced far in advance (2). This means that in order to be pedantically correct about the real number of seconds passed since the Unix epoch, you should probably add the leap seconds to the result obtained above for applications that rely on this. Windows is blissfully unaware of Leap Seconds (3)(4), and so will just have the notion of time as it receives it from its NTP master (I believe the default for a non-domain connected machine is ), which is probably serving up UTC including leap seconds. Net DateTime has no provisions for Leap Seconds, but will simply rely on the OS time. Since 1972, UTC has included "leap seconds", and we have had a total of 25 of them so far. a system for describing points in time, defined as the number of seconds elapsed since midnight Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds." (1) Long uni圎pochTime = 64(timeDifference.TotalSeconds) Net on a Windows system.įor nearly all practical cases and assuming the current time is past the Unix Epoch you could indeed take System.TimeSpan timeDifference = DateTime.UTCNow. I didn't really see any way to get around it than doing the string manipulation of the date conversion unfortunately.There is an interesting twist when you want to know the Unix Epoch time in. It seems as though influxdb just happens to be using a different type of precision then most python modules. # Put whatever rows the data appears in and the row you want the data to go in hereĪs to why this is happening, after reading this it seems like you aren't the only one getting frustrated by this issue. SecondsTimestamp = time.mktime((s, "%d/%m/%y %H:%M").timetuple()) It will take whatever csv file you put where "old.csv" is and create a second csv with the timestamp in nanoseconds. I didn't have a test csv to try this on, but it will likely work for you. Something like this should work to solve your current problem. Although I would be grateful to responses that can do both explain the issue and what I am seeing and why as well as ideas on how to take a CSV with one column that contains time stamps that appear as "4/1/17 2:00" and convert them to timestamps that appear as "1491030000000000000" either in a separate file or in a second column. I need to be able to convert that to the proper format that InfluxDB needs "1491030000000000000" to insert all these old measurements.Ī better understanding of what is going on and why is more important than how to programmatically solve this in Python. Every day at 2 am there is a measurement. I have a CSV file with tons of old timestamps that are simply, "4/1/17 2:00". But I would like to know why I can't seem to generate the same precision level in just one conversion. I suppose there are a few ways to do this programmatically within Python if it's as simple as adding on nine 0's to the result. If I try to enter a measurement into InfluxDB using the result Python gives me it ends up showing as: 1491030000 = T00:00:01.49103Z I am assuming that is related to the precision, InfluxDB does things down to nanosecond I think? Python Result: 1491030000 The last two samples above at least appear to give me the same number, but it's much shorter than what InfluxDB has. > print "Epoch Seconds:", time.mktime(t.timetuple()) I cannot seem to generate that same timestamp through Python, however.įor instance, I've tried a few different ways: > calendar.timegm(time.strptime(' 02:00:00', '%m/%d/%Y %H:%M:%S')) If I view that measurement in InfluxDB using the -precision rfc3339 it appears as: If I view a measurement in InfluxDB, I see time stamps such as: 1491030000000000000 Let me start by saying I am trying to use the same date and time in all tests: Apat 2:00AM CDT I've been trying to figure out how to generate the same Unix epoch time that I see within InfluxDB next to measurement entries.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |