in reply to Time Conversion Help
Greetings LostS,
The following isn't really a super-cool way to do this, but it seems to work in the test cases I've run. I'm sure merlyn or others could come up with something far smaller and better. But here it is:
#!/usr/bin/perl -w use strict; use Time::Local; my $original_time = '04/18/00 11:10 AM'; my ($mon, $mday, $year, $hours, $min, $mer) = split(/ |\/|:/, $origina +l_time); $hours += 12 if ($mer eq 'PM'); if ($year < 50) { $year += 2000; } else { $year += 1900; } my $unix_time = timelocal(0, $min, $hours, $mday, $mon - 1, $year); my $normal_time = localtime($unix_time); print "$unix_time == $normal_time\n";
-gryphon
code('Perl') || die;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Time Conversion Help
by LostS (Friar) on Sep 26, 2001 at 00:58 UTC |