Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
General
cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert number of seconds in to date OR vice versa

SOLVED
Go to solution
Manju Kampli
Trusted Contributor

How to convert number of seconds in to date OR vice versa

Dear Friends,

I am trying to write some scripts for ITO and see the date and time of the message received and compare it with the local time. if the message is sitting there for more than 30 mins I want to generate some alerts for operatiors.

This date filed in the IT/O database is in the form of seconds. It stores the date in number of seconds Since 1st Jan 1970. It means the current entry will be (60 * 60 min * 24 Hr * 365 days* 31 yrs ) seconds OR something similar
.
looks strange isn't it.... Well.. IT/O must be running some commands to calculate this seconds to date before displaying it on the message browser.

I want to know how can convert these seconds in to date so that I can compare it with current date and time. what commands I can use to get the current date in to number of seconds OR seconds available in the database in to date format

Thanks for your time

Cheers,
Manju
Never stop "LEARNING"
4 REPLIES
Highlighted
David Sullivan_1
Occasional Visitor

Re: How to convert number of seconds in to date OR vice versa

Hello!

Check out this URL http://www.oase-shareware.org/shell/links/index.html#archives scan for timeinseconds

Hope it helps!

Dave
David Sullivan_1
Occasional Visitor

Re: How to convert number of seconds in to date OR vice versa

Sorry, wrong url...
http://www.zipworld.com.au/~cs/scripts/
scroll down to timeinseconds...


Dave
Herve BRANGIER
Respected Contributor

Re: How to convert number of seconds in to date OR vice versa

Hi,

You can do that with a small part of C code (
see at the end to have an example). You can
use some C functions to do this (man ctime to
have all informations needed).
Compile with : cc
And start with : ./a.out

#include

main (nargs,args)
int nargs;
char ** args;
{
/* Here you translate args 1 : first time entered in seconds */
time_t my_time1 = atoi (args[1]);
/* Here you translate args 2 : second time entered in seconds */
time_t my_time2 = atoi (args[2]);

/* Now you can display dates using local time parameters like timezone,
summer time,... */
printf ("\nThe first date in parameter is : %s\n",asctime (localtime (&my_time1)));
printf ("\nThe second date in parameter is : %s\n",asctime (localtime (&my_time2)));

}


Bye,

Herve

Robin Wakefield
Honored Contributor
Solution

Re: How to convert number of seconds in to date OR vice versa

perl -e 'print time,"\n"'

will display the # secs since 1/1/70. Then use "bc" or your favourite unix number crunching command to work out the difference from your ITO figure.

Robin.