0
  1. how can I determine machine time in seconds on unix O/S? (i can't use 'date +%s', it's not POSIX).
  2. what functions exist for date and epoch time in second?
  3. by using date "+%format" how can i subtract 1-2 hour from present hour?

Regards

1

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

4 Comments

it can be use in shell script? it recieve value?
Sorry, I assumed you were using C. I don't see what's wrong with date +%s; I'm using Mac OS X and it works here.
A little searching shows that Solaris is a little odd in this respect. This may be helpful, but I'm not sure: solarisjedi.blogspot.com/2006/06/…
Oh, and I forgot to say: you may need to use platform detection. It sucks, but so does Solaris not supporting date +%s.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.