Operating System - HP-UX
1834532 Members
3391 Online
110069 Solutions
New Discussion

Re: Convert a date in seconds or viceversa

 
SOLVED
Go to solution
Massimo_20
Frequent Advisor

Convert a date in seconds or viceversa

Hi All,
I need to convert a data (for example - yy mm dd hh mm ss - 2003 11 08 10 30 21) in seconds or viceversa. Are there scripts or commands that already do it ?


Max
7 REPLIES 7
Alzhy
Honored Contributor

Re: Convert a date in seconds or viceversa

Use the PERL time functions... time, localtime... etc.. there should be tons of examples out there...

If developing tools on UNIX -- it is often advantageous to use time expresed in EPOCH seconds.... perl -e "print time" prints the current time in EPOCH seconds...
Hakuna Matata.
Massimo_20
Frequent Advisor

Re: Convert a date in seconds or viceversa

Hi Nelson,
can you suggest me any web site where I can some examples ?
Alzhy
Honored Contributor

Re: Convert a date in seconds or viceversa

Just some of many in a Google Search for "PERL Time Functions":

http://www.aota.net/Script_Installation_Tips/perltime.php4

And a sample PERL code (converts June 3, 2003 8:00:00):

#!/usr/bin/perl
use Time::Local;
$time=timelocal(8,00,00,3,5,103);
#print `date`;
#print time;
print "\n";
print $time;
print "\n";
Hakuna Matata.
Darren Prior
Honored Contributor
Solution

Re: Convert a date in seconds or viceversa

Hi,

Here's a quick method to convert from seconds since Epoch to a readable date:

echo "0d920537497=Y" | adb

obviously replace the 920537497 with your seconds value.

regards,

Darren.
Calm down. It's only ones and zeros...
Massimo_20
Frequent Advisor

Re: Convert a date in seconds or viceversa

Hi All,
thank u very much. Now I have the date in seconds with this perl's code :
$newtime = timelocal($secondi,$minuti,$ora,$giorno,$mese,$anno).

I don't found the function that convert the seconds in date.

Can somebody help me ?
Tim D Fulford
Honored Contributor

Re: Convert a date in seconds or viceversa

try the following, see the bottom part

http://www.perl.com/pub/a/2003/03/13/datetime.html

Tim
-
Jean-Luc Oudart
Honored Contributor

Re: Convert a date in seconds or viceversa

to convert seconds to date.
(man ctime)

"convtime.c" 11 lines, 191 characters
#include
#include
#include

main(int argc, char **argv)
{
long l1;
l1=atol(argv[1]);
printf("%s\n",ctime(&l1));
}
cc convtime.c -o convtime
convtime 920537497
Thu Mar 4 08:51:37 1999

Rgds,
JL

fiat lux