AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
  • 1.  Convert UTC time to local time ?

    Posted Thu January 07, 2010 01:25 AM

    Originally posted by: Vilius


    Hello,

    Using AIX6.1 box.
    I have UTC time value and need to convert it to local time value - I mean time zone and DST should be taken into consideration.
    I hope it could be done using shell environment - I don't want to write a program.

    thanks
    Vilius


  • 2.  Re: Convert UTC time to local time ?

    Posted Thu January 07, 2010 07:02 AM

    Originally posted by: j.gann


    I assume your time value is sth. like below. if you have gnu date installed:

    $ date -u
    Thu Jan 7 11:46:57 UTC 2010
    $ date -d "Thu Jan 7 11:46:57 UTC 2010" +"%T %D"
    12:46:57 01/07/10

    gnu date is available from the linux toolbox or on the hmc commandline.
    Cheers
    Joachim


  • 3.  Re: Convert UTC time to local time ?

    Posted Sun January 10, 2010 09:45 PM

    Originally posted by: SystemAdmin


    Select a timezone using the TZ variable, then run the date command. If you do not wish it to affect your environment, then run in a subshell;
    e.g.

    (TZ=EST-10AEDT; date)

    To run for Australian Eastern Daylight Saving timezone.


  • 4.  Re: Convert UTC time to local time ?

    Posted Tue September 25, 2018 10:27 AM

    Originally posted by: Satish J L


    Hi, I have developed a shell code which will convert CET to UTC that will not affect during the DST schedules. You just modify the logic accordingly from UTC to your timezone using this code's logic, I'm quite busy to change it. If you want I can change it and give.

     

    function RDTCTR 
      {            
                           if [[ $TIMEZONE == "RDT" ]] #|| [[ $TIMEZONE == "UTC-5" ]] || [[ $TIMEZONE == "UTC-4" ]]
                           then
       ch=0
       cm=0
       if [[ $(TZ=CET date|awk '{print $5}') == "CEST" ]]
       then 
       echo $1 |sed 's/-/./g'|awk -F'.' '{print $1" "$2" "$3" "$4" "$5" "$6" "$7}'|read ye mo dt ho mi se ze
       case $ho in
       '00') hou=24
    ch=1
    cm=0  ;;
       '01') hou=25
            ch=1
            cm=0  ;;
         *) hou=$ho
    ch=0
    cm=0  ;;
       esac
       hour=$(expr $hou - 2)
       else
           if [[ $(TZ=CET date|awk '{print $5}') == "CET" ]]
           then
               echo $1|sed 's/-/./g'|awk -F'.' '{print $1" "$2" "$3" "$4" "$5" "$6" "$7}'|read ye mo dt ho mi se ze
       case $ho in
       '00') hou=24
    ch=1
    cm=0  ;;
    *)  hou=$ho
    ch=0
    cm=0  ;;
       esac    
       hour=$(expr $hou - 1)
    fi
          fi
          if [[ ch -eq 1 ]]
    then
       echo "$ho of CET and $hour of UTC falls in midnight"
       if [[ $dt == "01" ]]
       then
       if [[ $mo == "01" ]]
       then
       yea=`expr $ye - 1 `
       mont=12
       dat=$(cal $mont $yea|awk 'NF {DAYS = $NF}; END {print DAYS}')
       else
       mont=`expr $mo - 1`
       if [[ `echo $mo | grep -c "^0"` -eq 1 ]] || [[ $mo -eq 10 ]]
       then
       mont=0${mont}
       fi
       dat=$(cal $mont $yea|awk 'NF {DAYS = $NF}; END {print DAYS}')
       yea=$ye
       fi
       else
       yea=$ye
       dat=`expr $dt - 1`
       mont=$mo
       fi
       else
       yea=$ye
       dat=$dt
       mont=$mo
       fi
       echo "$yea-$mont-$dat-$hour.$mi.$se.$ze"
       echo $1
       fi
       }

     

    You call it by the function:

    RDTCTR 2018-01-01-00.57.00.000000