I need to convert milliseconds to time irrespective of time zone.
Below is sample code
i := 1481462220
tm := time.Unix(i, 0)
Currently time.Unix returns time specific to my machine's zone. So, if I change time zone of my machine, it returns a different time. What I need is time should be same irrespective of time zone of machine.
As per GoDoc time.Unix :
Unix returns the local Time corresponding to the given Unix time, sec
seconds and nsec nanoseconds since January 1, 1970 UTC.
Hence to get the same time across machines you need to convert the returned local time using time.Time.UTC()
So in this case it would be tm.UTC().
You can use
tm.UTC()
UTC() returns tm with the location set to UTC.
Related
I have a simple NTP client that gets the value from an NTP server every 15 minutes. All of the values are calculated as per the NTP spec to account for the delay in the request and response.
I am not correcting the system clock at this time but each time getting the offset value of the uncorrected system time to the NTP time. I am getting values (in seconds) like on subsequent polls...
0.0017
0.0006
for offset times.
Is there a formula to calculate a drift of this particular clock at all? In these examples all the drift calculations are +0 so the clock is running fast by a small amount but by how much?
For example say the offset was a consistent 0.9 seconds with a 15 minute NTP poll time?
Say I have a a series of timestamps (from visitor impressions), and it looks like (omitting dates):
01:02:13
01:03:29
01:04:34
02:19:29
09:45:10
09:46:20
.....
In the above case, I'd want to sum up the time passed from the first 4 timestamps (1 to 2AM), and separate them from the 9AM events.
Is there a clever way to estimate combined active time, other than utilizing a timeout (say a 300+ seconds timeout indicates a new session). If not, what's a standard / good timeout to use?
I'm trying to convert the normal 24 hour system to a 20 hour system in JavaScript or html
there seems to be problems and I don't know how to fix them, the program code as a whole works ok but it's not accurate in the area of displaying the proper time
can someone help me.
24hrs per day to 20hrs
60 minutes per hour to 40 minutes per hour
60 seconds per minute to 80 seconds per minute
1000 milliseconds per second to 1350 milliseconds per second
I have been working with the code that is supposed to get the milliseconds from 1/1/1970 to make things hopefully simple but like I said the program isn't working quite right, I do have a table that lets me know what normal time would be at each changed hour but that's all the info I have
Check this Fiddle:
http://jsfiddle.net/z4s7j9vL/1/
My approach was to get the timestamp difference between the current time and midnight of the same day:
millis = ts - clone.getTime();
This way you get how many milliseconds have passed this day and you can do your conversion from there. This is limited to converting time only, but if months and years followed the same principles you could just convert the same way from the current timestamp.
I have programmed a punch clock system. I need to modify it to comply with California overtime rules such that if someone works more than 8 hours in 24, they receive overtime. I am stumped on how to go about doing this that is not computationally intensive.
Our punches are rounded to 15 minute intervals, meaning people will punch in at 8:00 AM, 8:15 AM, 8:30 AM and so on.
So if someone starts at 8am on Monday, works a total of 8 hours, and starts at 7am on Tuesday, they get an hour of overtime?
Assume you have a list of start/stop date time pairs for a given employee. This list has to include start/stop date time pairs from the previous time period.
Get the first start/stop date time pair from the current pay period.
Get the previous start/stop date time pair.
Determine the interval in hours and fractions of hours between the previous start and the current start.
If the interval is greater than or equal to 24, get the next current pay period start/stop date time pair, and go to 2. Exit if no more start/stop date time pairs.
Else, if the interval is less than 24, calculate the overtime in the current start/stop date time pair. The lessor of (24 - interval) and the amount of hours worked in the current start/stop date time pair.
Get the next current pay period start/stop date time pair. Exit if no more start/stop date time pairs.
Hold the previous start/stop date time pair.
Go to 3.
how can I determine machine time in seconds on unix O/S? (i can't use 'date +%s', it's not POSIX).
what functions exist for date and epoch time in second?
by using date "+%format" how can i subtract 1-2 hour from present hour?
Regards
Try the time function in time.h. For example:
time_t the_time=time(NULL);
// the_time now contains the number of seconds since the epoch
To get a time in the past, just subtract the number of seconds. Since there are 3600 seconds in an hour, to go an hour back, just subtract 3600.