IP

LINUX HACK 9

Hack 9.
Display Current Date and Time in a Specific Format:
 
Following are different ways of displaying the current date and time in various formats:

$ date
Thu Jan 1 08:19:23 PST 2009
$ date --date="now"
Thu Jan 1 08:20:05 PST 2009
$ date --date="today"
Thu Jan 1 08:20:12 PST 2009
$ date --date='1970-01-01 00:00:01 UTC +5 hours' +%s
18001
$ date '+Current Date: %m/%d/%y%nCurrent Time:%H:%M:%S'
Current Date: 01/01/09
Current Time:08:21:41
$ date +"%d-%m-%Y"
01-01-2009
$ date +"%d/%m/%Y"
01/01/2009
$ date +"%A,%B %d %Y"
Thursday,January 01 2009
Following are the different format options you can pass to the date command:
o %D date (mm/dd/yy)
o %d day of month (01..31)
o %m month (01..12)
o %y last two digits of year (00..99)
o %a locale’s abbreviated weekday name (Sun..Sat)
o %A locale’s full weekday name, variable length (Sunday..Saturday)
o %b locale’s abbreviated month name (Jan..Dec)
o %B locale’s full month name, variable length (January..December)
o %H hour (00..23)
o %I hour (01..12)
o %Y year (1970…)



0 comments:

Post a Comment