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

Jens
  • 69,818
  • 15
  • 125
  • 179
shamir chaikin
  • 681
  • 1
  • 6
  • 9

1 Answers1

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.

icktoofay
  • 126,289
  • 21
  • 250
  • 231
  • it can be use in shell script? it recieve value? – shamir chaikin May 09 '11 at 06:22
  • 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. – icktoofay May 09 '11 at 06:23
  • A little searching shows that Solaris is a little odd in this respect. This may be helpful, but I'm not sure: http://solarisjedi.blogspot.com/2006/06/solaris-date-command-and-epoch-time.html – icktoofay May 09 '11 at 06:27
  • Oh, and I forgot to say: you may need to use platform detection. It sucks, but so does Solaris not supporting `date +%s`. – icktoofay May 09 '11 at 06:28