----- Original Message ----- From: "Jeff Pang" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners
To: <beginners@perl.org>
Sent: Thursday, March 09, 2006 10:09 AM
Subject: how to translate time string


Hello,list,

Maybe it's a simple problem,but I don't know how to do it.

I have a time string,for example:
Thu Mar  9 23:04:03 2006

How can  I get it translated to unix timestamp,for example:
1141916656

Thanks.

--
Jeff Pang
NetEase AntiSpam Team
http://corp.netease.com

How about Time::Local?

#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;

my %month;
@month{ qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/ } = 0..11;

my $date = "Thu Mar  9 23:04:03 2006";

my (undef, $month, $day, $h, $m, $s, $year) = split /\W+/, $date;

my $time = timelocal($s,$m,$h,$day,$month{$month},$year);

print $time,$/;

print scalar localtime $time;


(Prints)
1141963443
Thu Mar  9 23:04:03 2006


Chris



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to