using date function in unix - epoch

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.

Related

How to remove a time period from another time period?

I wanna remove just a time period without a date, from another time period.
for example, assume, I have a time period like 08:00 to 16:00, and I wanna remove 10:00 to 12:00 period from that period time.
actually, the first period of time has been converted to two periods of time. 08:00 to 10:00 and 12:00 to 16:00.
What is the best way to implement it? it should be implemented just with if else? or it has another best way to implement it.

golang : convert milliseconds to time

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.

How does dbms_scheduler running every x hours/ minutes handle daylight saving time?

I have a dbms_scheduler job which has to run every 4 hours, in timezone 'Europe/Berlin'
My question is: what happens on days with a change in daylight saving time?
Let's say, last runtime was 01:00 AM. Not time either is set from 02:00AM to 03:00AM or from 03:00AM to 02:00AM.
Is the next runtime of my job after 3 hours in the first and after 5 hours in the second case or will it be just after 4 hours, regardless of the change in daylight saving time?

JavaScript/html time

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.

How to determine programming logic for working hours, taking overtime into consideration.

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.

Resources