UTC time conversion to local time
am 15.08.2008 05:13:00 von Bilashi Sahu
Hi,
I am trying to convert UTC (In seconds) time to local Time.
I will appreciate if anybody has some hints to do this.
I have code like this, it does not work properly
Here cds_date is in UTC seconds and $cmpn_date is in local time
Just comparing if both of the same
Thanks,
Bilashi
#check date
sub checkDate () {
my ($cds_date, $cmpn_date, $fhlog, $result) = @_;
my ($g_day, $g_mon, $g_year, $g_hr, $g_min, $g_sec, $g_msec, $g_ampm) = split(/[-\s\.]/, $cmpn_date); $g_year += 2000;
my @abbr = qw( JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC );
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($cds_date);
$year += 1900;
if($g_ampm eq "PM") {
$g_hr += 12;
}
$g_hr = 0 if($g_ampm eq "AM" && $g_hr == 12);
$hour = ($hour + 7) if ($g_hr < 17);;
if ($g_year == $year &&
($g_day == $mday) &&
($abbr[$mon] eq $g_mon)
&& $g_hr == $hour && $g_min == $min && $g_sec == $sec) {
#$g_hr == $hour && $g_min == $min && $g_sec == $sec) {
} else {
$$result = "F";
}
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: UTC time conversion to local time
am 15.08.2008 05:57:05 von Michael Ellery
use DateTime;
use DateTime::Format::HTTP;
???
-Mike
Bilashi Sahu wrote:
> Hi,
> I am trying to convert UTC (In seconds) time to local Time.
> I will appreciate if anybody has some hints to do this.
> I have code like this, it does not work properly
> Here cds_date is in UTC seconds and $cmpn_date is in local time
> Just comparing if both of the same
>
>
> Thanks,
>
> Bilashi
>
>
> #check date
> sub checkDate () {
> my ($cds_date, $cmpn_date, $fhlog, $result) = @_;
> my ($g_day, $g_mon, $g_year, $g_hr, $g_min, $g_sec, $g_msec, $g_ampm) = split(/[-\s\.]/, $cmpn_date); $g_year += 2000;
> my @abbr = qw( JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC );
> my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($cds_date);
> $year += 1900;
> if($g_ampm eq "PM") {
> $g_hr += 12;
> }
> $g_hr = 0 if($g_ampm eq "AM" && $g_hr == 12);
> $hour = ($hour + 7) if ($g_hr < 17);;
>
> if ($g_year == $year &&
> ($g_day == $mday) &&
> ($abbr[$mon] eq $g_mon)
> && $g_hr == $hour && $g_min == $min && $g_sec == $sec) {
> #$g_hr == $hour && $g_min == $min && $g_sec == $sec) {
> } else {
> $$result = "F";
> }
>
>
>
>
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
>
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: UTC time conversion to local time
am 15.08.2008 06:01:25 von Bill Luebkert
Bilashi Sahu wrote:
> Hi,
> I am trying to convert UTC (In seconds) time to local Time.
> I will appreciate if anybody has some hints to do this.
> I have code like this, it does not work properly
> Here cds_date is in UTC seconds and $cmpn_date is in local time
> Just comparing if both of the same
You're starting to piss me off dude. You didn't follow my suggestions
at all when it comes to posting a problem. This will be my last reply
if you don't learn to post properly and save us all some work on your
problems.
> #check date
> sub checkDate () {
^^ Why are you using prototyping () ?
> my ($cds_date, $cmpn_date, $fhlog, $result) = @_;
> my ($g_day, $g_mon, $g_year, $g_hr, $g_min, $g_sec, $g_msec, $g_ampm) = split(/[-\s\.]/, $cmpn_date); $g_year += 2000;
> my @abbr = qw( JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC );
> my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($cds_date);
> $year += 1900;
> if($g_ampm eq "PM") {
> $g_hr += 12;
> }
> $g_hr = 0 if($g_ampm eq "AM" && $g_hr == 12);
> $hour = ($hour + 7) if ($g_hr < 17);;
What's the above line for ?
> if ($g_year == $year &&
> ($g_day == $mday) &&
> ($abbr[$mon] eq $g_mon)
> && $g_hr == $hour && $g_min == $min && $g_sec == $sec) {
> #$g_hr == $hour && $g_min == $min && $g_sec == $sec) {
> } else {
> $$result = "F";
> }
Please post properly with a COMPLETE test case:
use strict;
use warnings;
use IO::Handle;
my $dbg = 1;
my $io = new IO::Handle;
my $fhlog = $io->fdopen(fileno (STDOUT), "w") or die;
my $cds_date = time;
my @t = localtime; # for debug
# I'm forcing a match in time here:
my $cmpn_date = sprintf "14-AUG-08 %u %u %u.001 PM",
$t[2] > 12 ? $t[2] - 12 : $t[2], $t[1], $t[0];
my $result = 0;
checkDate ($cds_date, $cmpn_date, $fhlog, \$result);
$fhlog->print("result='$result'\n");
exit;
# check date
sub checkDate {
my ($cds_date, $cmpn_date, $fhlog, $result) = @_;
my @abbr = qw(JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC);
my ($g_day, $g_mon, $g_year, $g_hr, $g_min, $g_sec, $g_msec, $g_ampm) =
split /[-\s\.]/, $cmpn_date;
$g_year += 2000;
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime (
$cds_date);
$year += 1900;
$g_hr += 12 if $g_ampm eq 'PM';
$g_hr = 0 if $g_ampm eq 'AM' && $g_hr == 12;
# $hour = $hour + 7 if $g_hr < 17; # whats this for ?
$$result = 'F';
if ($g_year == $year && $g_day == $mday && $abbr[$mon] eq $g_mon &&
$g_hr == $hour && $g_min == $min && $g_sec == $sec) {
$$result = 'T';
}
}
__END__
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs