Attachment 'utime2ymd.txt'

Download

   1 #!/bin/sh
   2 usage="Usage: utime2ymd <timestamp> [local|gmt]
   3 \n\nConvert 10-digit Unix timestamp to yyyymmdd.hhmmss format
   4 \n use local time zone (default) or UTC/GMT"
   5 [ $1 ] || { echo -e $usage; exit 1 ; }
   6 
   7 unixtime=`echo $1|cut -c -10`
   8 
   9 if [ $2 ] 
  10 then qual2=`echo $2|awk '{print tolower($1)}'`
  11     if [ "$qual2" = "gmt" ] 
  12     then thetime=`perl -e "print scalar(gmtime($unixtime))"`
  13     fi
  14 else
  15     qual2="local"
  16     thetime=`perl -e "print scalar(localtime($unixtime))"`
  17 fi 
  18 
  19 YYYYMM=`echo $thetime | awk '{print $5 $2}' \
  20     | sed 's/Jan/01/;s/Feb/02/;s/Mar/03/;s/Apr/04/;s/May/05/;s/Jun/06/;
  21            s/Jul/07/;s/Aug/08/;s/Sep/09/;s/Oct/10/;s/Nov/11/;s/Dec/12/'`
  22 
  23 DD=`echo $thetime | awk '{printf("%02d",$3)}'`
  24 
  25 hhmmss=`echo $thetime | awk '{print $4}' | sed 's/://g'`
  26 
  27 echo "$YYYYMM$DD.$hhmmss $qual2"

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.