I have some dates in the format scalar localtime() which I want to convert to create a timestamp.
I thought this would be quite simple, as the scalar localtime() is automatic and so, I thought, would be the re-conversion. However much reading left me with the impression that I had to do a little more work to make this conversion.
I came up with the following script:
which appears to give me the correct results. I just thought that I'd ask the question - did I miss something, is there a one or two liner which would do this job?#!/usr/bin/perl -wT use strict; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI ':standard'; use Time::Local; my $input = param('date'); print "Content-type: text/html\n\n"; my $ILLEGAL_CHARS = qr/[^\w:]/; if ($input =~ /$ILLEGAL_CHARS/;) { print "You do not have the right to enter that information"; } my @date = split (/ /, $input); my ($day,$mon,$mday,$hms,$year) = @date; my @date1 = split (/:/, $hms); my ($hour,$min,$sec) = @date1; my %mon_writ = ( Jul => '6', Aug => '7', Sept => '8', Oct => '9', ); $mon = $mon_writ{key}; ($sec, $min, $hour, $mday, $mon, $year) =~ s/^0+//; $year = $year - 1900; my $TIME = timegm($sec, $min, $hour, $mday, $mon, $year); print $TIME;
If there are improvements I could make to this I'd also be grateful to know of them
In reply to scalar localtime() to timestamp by jonnyfolk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |