date time



For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
 
# date  -s   "2 OCT 2006 18:00:00"
 
OR

# date --set="2 OCT 2006 18:00:00"

You can also simplify format using following syntax:
 
# date +%Y%m%d -s "20081128"

$ date --date="12/2/2014"
Tue Dec  2 00:00:00 PST 2014

$ date --date="2 Feb 2014"
Sun Feb  2 00:00:00 PST 2014

$ date --date="Feb 2 2014"
Sun Feb  2 00:00:00 PST 2014


Linux Set Time
To set time use the following syntax:

# date  +%T  -s  "10:13:13"

Set timezone using /etc/localtime configuration file [any Linux distro]

Often /etc/localtime is a symlink to the file localtime or to the correct time zone file in the system time zone directory.

Generic procedure to change timezone under Linux

Cd to /etc, run:
# cd /etc
Create a symlink to file localtime:
# ln -sf /usr/share/zoneinfo/EST localtime
OR some distro use /usr/share/zoneinfo/dirname/zonefile format (Red hat and friends):
# ln -sf /usr/share/zoneinfo/EST localtime
OR if you want to set up it to Asia/Kathmandu
# ln -sf /usr/share/zoneinfo/Asia/Kathmandu localtime
Various Date Command Formats
You can use formatting option to display date command in various formats using the following syntax:
$ date +%<format-option>
The following table displays various date command formatting options.
Format options
Purpose of Option
Output
date +%a
Displays Weekday name in short (like Mon, Tue, Wed)
Thu
date +%A
Displays Weekday name in full short (like Monday, Tuesday)
Thursday
date +%b
Displays Month name in short (like Jan, Feb, Mar )
Feb
date +%B
Displays Month name in full short (like January, February)
February
date +%d
Displays Day of month (e.g., 01)
07
date +%D
Displays Current Date; shown in MM/DD/YY
02/07/13
date +%F
Displays Date; shown in YYYY-MM-DD
2013-02-07
date +%H
Displays hour in (00..23) format
23
date +%I
Displays hour (01..12) format
11
date +%j
Displays day of year (001..366)
038
date +%m
Displays month (01..12)
02
date +%M
Displays minute (00..59)
44
date +%S
Displays second (00..60)
17
date +%N
Displays nanoseconds (000000000..999999999)
573587606
date +%T
Displays time; shown as HH:MM:SS
Note: Hours in 24 Format
23:44:17
date +%u
Displays day of week (1..7); 1 is Monday
4
date +%U
Displays week number of year, with Sunday as first day of week (00..53)
05
date +%Y
Displays full year i.e. YYYY
2013
date +%Z
alphabetic time zone abbreviation (e.g., EDT)
IS

No comments:

Post a Comment