This is pretty straightforward, but I couldn't find a response and figured that others might have the same question.
I have a Unix timestamp as a float, that includes a decimal value for fractions of seconds. What's the conversion factor to pass this float as two separate integers to the time
package's time.Unix(sec int64, nsec int64)
function, without losing the decimal precision?
The getTime method returns the number of milliseconds since the Unix Epoch (1st of January, 1970 00:00:00). To get a Unix timestamp, we have to divide the result from calling the getTime() method by 1000 to convert the milliseconds to seconds. What is this?
Current Unix Timestamptime() function by itself returns the Unix timestamp as a float , with any value to the right of the decimal point representing fractions of a second.
No. epoch time is how time is kept track of internally in UNIX. It's seconds, counting upward from January 1st, 1970. This number hit 1 million (1,000,000) in March of 1973, and will hit one billion (1,000,000,000) on Sun Sep 9 01:46:39 2001 UTC.
Unix timestamps are always integers.
sec, dec := math.Modf(timeFloat);
time.Unix(int64(sec), int64(dec*(1e9)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With