Popular Posts

Jun 20, 2018

Epoch Seconds to date & date to epoch seconds in Linux/UNIX

Epoch Seconds to date & date to epoch seconds in Linux/UNIX

APPLIES TO : All UNIX, Linux , HP-UX


1.        Convert Epoch seconds To date and Time format - Linux
                  date -d @1268727836

2.        Convert Epoch seconds To date and Time format - perl commands
                  perl -le 'print scalar localtime $ARGV[0]' 1528295738
                      Wed Jun  6 15:35:38 2018
                  perl -e 'print scalar(localtime(1528295738)), "\n"'
                      Wed Jun  6 15:35:38 2018
                  perl -leprint\ scalar\ localtime\ 1528295738
                      Wed Jun  6 15:35:38 2018

3.        Convert Epoch seconds To date and Time - Linux awk command
                  echo 1268727836 | awk '{print strftime("%c",$1)}'
                      Wed Jun  6 15:35:38 2018

4.        Print Current date and time in epoch seconds - Linux
                  date +%s
                      1528295738

5.        Current date and time in epoch seconds - Solaris
                  nawk "BEGIN{print srand}"
                      1528295738

6.        Current epoch seconds in Solaris and HPUX
                  perl -e 'print time()' ; printf "\n"
                      1528295738

7.        Find current epoch seconds using perl script
                  Judi-Dev-01 #  vi current_epoch.pl
                      #!/bin/perl
                      print "Current (epoch) time: " . time() . "\n";
                  Judi-Dev-01 # 
                  Judi-Dev-01 # ./current_epoch.pl
                      Current (epoch) time: 1529498830
                  Judi-Dev-01 #

8.        Convert date and time to epoch seconds
                  perl -e "use Time::Local; print timelocal($C_SEC, $C_MIN, $C_HOURS, $C_DAY, $C_MONTH1-1, $C_YEAR)"
                  perl -e "use Time::Local; print timelocal(01, 01, 00, 16, 6-1, 2018)" ; printf "\n"
                      Sat Jun 16 00:01:01 2018

9.        Display only time
                  date +"%T"
                      16:31:42

10.        Display date and time in local format (locale)

                  date +"%c"
                      Wed Jun 20 16:32:01 2018

11.        To get previous date in solaris (24 Hours per day) Calculate accordingly (Today is 16-Jun-2018)
                  TZ=GMT+24 date +%d-%m-%Y
                      15-06-2018
                  TZ=GMT+48 date +%d-%m-%Y
                      14-06-2018

11.        To get previous day in Solaris (86400 seconds for one day) Calculate accordingly
                  perl -MPOSIX=strftime -le 'print strftime("%d", localtime(time-86400))'
                      15-Jun-2018

11.        To get previous two days date in Solaris (86400 seconds for one day) Calculate accordingly
                  perl -MPOSIX=strftime -le 'print strftime("%d-%b-%Y", localtime(time-172800))'
                      18-Jun-2018



~Judi~







No comments:

Post a Comment

Popular Posts