Christopher Juckins

SysAdmin Tips, Tricks and other Software Tools

User Tools

Site Tools


manipulating_date_strings

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
manipulating_date_strings [2010/10/22 14:48] juckinsmanipulating_date_strings [2022/05/07 12:33] (current) juckins
Line 7: Line 7:
  
 Output is: Thursday, 21 October 2010 22:21:49 UTC Output is: Thursday, 21 October 2010 22:21:49 UTC
 +</code>
 +
 +Querying a specific timezone to determine DST:
 +<code>
 +[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
 +</code>
 +
 +Manipulating date/time from NWS text products:
 +<code>
 +If you take the date/time line from a current text product, such as:
 +
 +806 PM EST TUE 3 JAN 2012
 +
 +Add a colon to the hour/minute:
 +
 +8:06 PM EST TUE 3 JAN 2012
 +
 +You can feed that string directly into the linux date command and
 +manipulate it forward and backward by any amount of time and then print
 +it out in the same format.
 +
 +Forward 6 hours:
 +$ date --date="8:06 PM EST TUE 3 JAN 2012 6 hours" "+%I%M %p %Z %a %d %b
 +%Y" | sed 's/^0//' | sed 's/\s0/ /g' | sed 's/./\u&/g'
 +206 AM EST WED 4 JAN 2012
 +
 +Forward 30 minutes:
 +date --date="8:06 PM EST TUE 3 JAN 2012 30 minutes" "+%I%M %p %Z %a %d
 +%b %Y" | sed 's/^0//' | sed 's/\s0/ /g' | sed 's/./\u&/g'
 +836 PM EST TUE 3 JAN 2012
 +
 +Backward 12 hours:
 +date --date="8:06 PM EST TUE 3 JAN 2012 -12 hours" "+%I%M %p %Z %a %d %b
 +%Y" | sed 's/^0//' | sed 's/\s0/ /g' | sed 's/./\u&/g'
 +806 AM EST TUE 3 JAN 2012
 +
 +The 1st sed strips any leading zeros at the beginning of the line, the
 +2nd sed strips any other leading zeros, and the final sed makes it all
 +UPPER.
 </code> </code>
  
 Other file stats info: Other file stats info:
 [[http://perldoc.perl.org/functions/stat.html]] [[http://perldoc.perl.org/functions/stat.html]]
 +
 +Using Linux 'date' to print a time:
 +<code>
 +[juckins@lightning: /var/www/html/amtrak_status]$ date --date="Sat Nov 19 2011 11:00 pm"
 +Sat Nov 19 23:00:00 EST 2011
 +</code>
 +
 +More examples of 'date' to compute a time based upon a given time and some offset value:
 +<code>
 +[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
 +
 +$date --date="yesterday 08:00 gmt" '+%y%m%d/%H%M'
 +121002/0800
 +
 +$ date --date="today 18:00 gmt" '+%y%m%d/%H%M'
 +121003/1800
 +
 +$ date --date="yesterday 08:00 edt" '+%y%m%d/%H%M'
 +121002/1200
 +
 +$ date -d @1446390000
 +Sun Nov  1 15:00:00 UTC 2015
 +</code>
 +
 +Converting from seconds and a different timezone:
 +  TZ=":US/Eastern" date -d @1651335000
 +  TZ=":America/Phoenix" date -d @1651335000
 +  TZ=":America/Phoenix" date --date='2022-05-04T14:00:00.000Z'
manipulating_date_strings.1287773295.txt.gz · Last modified: 2010/10/22 14:48 by juckins