Christopher Juckins

SysAdmin Tips, Tricks and other Software Tools

User Tools

Site Tools


manipulating_date_strings

This is an old revision of the document!


Print file modification times:

$filename = "201010211800_a.png";
$mtime = (stat $filename)[9];
chomp($mtime);
$mtime_date = `/bin/date --date='Jan 1, 1970 00:00:00 +0000 + $mtime seconds' '+%A, %d %B %Y %H:%M:%S %Z'`;

Output is: Thursday, 21 October 2010 22:21:49 UTC

Querying a specific timezone to determine DST:

[cjuckins@lnxopc2: ~]$ zdump America/New_York
America/New_York  Tue May  3 13:41:20 2011 EDT

[cjuckins@lnxopc2: ~]$ zdump America/Los_Angeles
America/Los_Angeles  Tue May  3 10:41:52 2011 PDT

Other file stats info: http://perldoc.perl.org/functions/stat.html

Using Linux 'date' to print a time:

[juckins@lightning: /var/www/html/amtrak_status]$ date --date="Sat Nov 19 2011 11:00 pm"
Sat Nov 19 23:00:00 EST 2011

More examples of 'date' to compute a time based upon a given time and some offset value:

[juckins@lightning: ~]$ date --date="sat nov 19 2011 6:00pm"
Sat Nov 19 18:00:00 EST 2011

[juckins@lightning: ~]$ date --date="sat nov 19 2011 6:00pm 1 hours 1 minutes"
Sat Nov 19 19:01:00 EST 2011

[juckins@lightning: ~]$ date --date="sat nov 19 2011 6:00pm -1 hours -1 minutes"
Sat Nov 19 16:59:00 EST 2011
manipulating_date_strings.1321804102.txt.gz · Last modified: 2011/11/20 10:48 by juckins