AIX

AIX

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

 View Only
  • 1.  display date/time command in AIX

    Posted Sun March 01, 2015 08:45 AM

    Originally posted by: John2006


    Hi All,

    I would like to display date and time in AIX command prompt by using "date". May I know that the "date" command can display past five minutes time? For example: the current time is "2015 Jan 11, 13:30". I would like the date command can show 2015 Jan 11 13:25". 

    Regards

    John



  • 2.  Re: display date/time command in AIX

    Posted Mon March 09, 2015 10:25 AM

    Originally posted by: Wouter Liefting


    I couldn't think of an easy way to do this with shell constructs and/or the date command only. However, in perl it's easy.

     

    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( time() - 5);

    print "$hour:$min:$sec";

     

    You can include perl code in the perl call with -e, so from the shell this would become:

    perl -e  ' ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( time() - 5); print "$hour:$min:$sec"; '

     

    Obviously the "- 5" is the offset, and the print "$hour:$min:$sec" can be modified to generate any output you need.

     

    Be aware that the $year is the current year minus 1900, and that $mon starts counting from 0. http://perldoc.perl.org/functions/localtime.html

     

    If you are happy with the default scalar output of localtime ( for example Mon Mar  9 15:03:18 2015 ) you could even do this:

    perl -e '$string = localtime( time - 5 ); print $string;'

     



  • 3.  Re: display date/time command in AIX

    Posted Sun March 15, 2015 08:27 PM

    Originally posted by: N.Venkat


    If you want to show 5 mins before from current time window  then you may use alias, and customize the command what output you want. with out disturb your current date settings

    else still its possible but depends on the server use. ( means in case if you use the server in real world still you need to customize using alias else its stand alone not in real world use, of course every one know easiest way to set date manually enter the time. )



  • 4.  Re: display date/time command in AIX

    Posted Wed June 10, 2015 05:08 AM

    Originally posted by: L.Sarrazin


    Hi,

    As I reviewed forum threads, I thought of the variant date command which comes from linux binaries; for example:

    
    root@nimtsm01(/usr/linux/bin)# oslevel -s
    6100-09-04-1441
    root@nimtsm01(/usr/linux/bin)# date ; /usr/linux/bin/date --date='1 min ago' +%y%m%d%M%S
    Wed Jun 10 11:05:42 CEST 2015
    1506100442
    

    Really useful for time travel.

    Regards

    L. Sarrazin



  • 5.  Re: display date/time command in AIX

    Posted Thu June 11, 2015 12:43 PM

    Originally posted by: GarlandJoseph


    lol...time travel, now if I could only get some flux capacitors and a  Delorian.



  • 6.  Re: display date/time command in AIX

    Posted Mon June 22, 2015 11:23 PM

    Originally posted by: pillow


    hi,

     

    perl -MPOSIX -le 'print strftime "%c", localtime(time()-300)'