Hack 7. Set System Date and Time

by Ramesh

To change the system date use:

  1. # date {mmddhhmiyyyy.ss}

omm – Monthodd – Dateohh – 24 hour formatomi – Minutesoyyyy – Yeaross – seconds

For example, to set system date to Jan 31st 2009, 10:19 p.m, 53 seconds

  1. # date 013122192009.53

You can also change system date using set argument as shown below.

  1. # date 013122192009.53
  2.  
  3. # date +%Y%m%d -s "20090131"
  4.  
  5. # date -s "01/31/2009 22:19:53"
  6.  
  7. # date -s "31 JAN 2009 22:19:53"
  8.  
  9. # date set="31 JAN 2009 22:19:53"

To set the time only:

  1. # date +%T -s "22:19:53"
  2.  
  3. # date +%T%p -s "10:19:53PM"