Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How do I find difference between two timestamps?

by tall_man (Parson)
on Nov 16, 2004 at 17:13 UTC ( #408171=note: print w/replies, xml ) Need Help??


in reply to How do I find difference between two timestamps?

The timegm function in Time::Local can convert a Zulu (GMT) time into a timestamp. Since your date formats are nonstandard, it would be simplest to break out the year, month, day, hours, minutes, and seconds with a regular expression or substrings, then do:
$time = timegm($sec,$min,$hour,$mday,$mon,$year);
These times can be subtracted to give differences in seconds. You'll have to subtract the milliseconds separately and add that to the difference.

Replies are listed 'Best First'.
Re^2: How do I find difference between two timestamps?
by tomhukins (Curate) on Nov 16, 2004 at 17:23 UTC
    Since your date formats are nonstandard

    Non-standard how? They conform to ISO 8601, which defines the international standard for expressing dates and times.

      That may be so according to the most recent 8601 standard, but as far as Perl is concerned it is not. For example, Date::Manip claims to be able to handle ISO 8601 date formats, but the following will fail:
      use strict; use Date::Manip; my $string = "2004-11-15T18:59:52.863Z"; my $date = ParseDate($string); print $date,"\n";
        Date::Manip claims to be able to handle ISO 8601 date formats, but the following will fail

        It seems Date::Manip only understands a subset of valid ISO 8601 formats. Again, I suggest the DateTime collection of modules that have been mentioned elsewhere in this discussion.

        The DateTime modules do a good job of dealing with dates, times, intervals, timezone differences, daylight savings time, and other things that make this type of programming more difficult than first appearances suggest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://408171]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2022-01-20 01:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (56 votes). Check out past polls.

    Notices?