HOW to convert date string to sec?

N

news.hinet.net

if i have a date string like 200407221405000 .
how to convert the string to sec from 1971/1/1 like time()?
 
A

A. Sinan Unur

if i have a date string like 200407221405000 .
how to convert the string to sec from 1971/1/1 like time()?

How about looking at the various Date:: modules on CPAN.

By the way, are you sure you have read

perldoc -f time
 
D

Dangerous Lunatic

news.hinet.net said:
if i have a date string like 200407221405000 .
how to convert the string to sec from 1971/1/1 like time()?

sub utc2seconds {
my $utc = shift @_;
my $YYYY = substr($utc,0,4);
my $MM = substr($utc,4,2);
my $DD = substr($utc,6,2);
my $hh = substr($utc,8,2);
my $mm = substr($utc,10,2);
my $ss = substr($utc,12,2);
return timegm($ss,$mm,$hh,$DD,$MM,$YYYY);
}
....
my $seconds = utc2seconds(200407221405000);
 
N

news.hinet.net

timegm is perl build-in function??


Dangerous Lunatic said:
sub utc2seconds {
my $utc = shift @_;
my $YYYY = substr($utc,0,4);
my $MM = substr($utc,4,2);
my $DD = substr($utc,6,2);
my $hh = substr($utc,8,2);
my $mm = substr($utc,10,2);
my $ss = substr($utc,12,2);
return timegm($ss,$mm,$hh,$DD,$MM,$YYYY);
}
...
my $seconds = utc2seconds(200407221405000);
 
T

Tore Aursand

if i have a date string like 200407221405000

What kind if date is that? 2004-07-22 14:05:000? I guess you added a '0'
too much at the end there.
how to convert the string to sec from 1971/1/1 like time()?

First of all, it's seconds since January 1st, 1970 you want. Secondly,
you don't need to install an extra module (if you have a fairly up-to-date
Perl installation); the Time::Local is there for you;

perldoc Time::Local
 
J

Joe Smith

news.hinet.net said:
i dont want to use module.
because i must install those module

How about *LOOKING* at a module from CPAN.
As in look at the source code and see how it's done.
-Joe
 
J

Johnny \Gandalf\ Brasseur

news.hinet.net said:
if i have a date string like 200407221405000 .
how to convert the string to sec from 1971/1/1 like time()?

You may also use the HTTP::Date module which almost answers your needs
it is also based on Time::Local.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top