Linux time zone and time modification

Source: Internet
Author: User
Modify the time zone: 1 & gt; find the corresponding time zone file/usr/share/zoneinfo/Asia/Shanghai and replace the current/etc/localtime file with this file. Or find the server that you think is standard time, and then # scproot@xxx.xxx.xxx.xxx:/etc/localtime/etc/localtim...

Modify the time zone:
1>
Find the corresponding time zone file/usr/share/zoneinfo/Asia/Shanghai
Replace the current/etc/localtime file with this file.
Or find the server that you think is the standard time, and then
# Scp root@xxx.xxx.xxx.xxx:/etc/localtime
2>
Modify the/etc/sysconfig/clock file:
ZONE = "Asia/Shanghai"
UTC = false
ARC = false

Modify date and time
1>
Use date to modify the date and time
# Date-s 08/24/2006
# Date-s 13:02:00
2>
Synchronizes the BIOS clock and forces the system time to be written to CMOS.
# Clock-w

In addition, use # hwclock-r to view Bois time
# Tzselect can be used to interactively modify the time zone


Linux system time zone modification
1. view the current time zone

# Vi/etc/sysconfig/clock
2. modify the time zone

Method (1) # tzselect method (2 Limited to RedHat Linux and CentOS) # timeconfig
3. copy the corresponding time zone file to replace the default time zone of the system.

# Cp/usr/share/zoneinfo/$ Main time zone/$ time zone/etc/localtime: # cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime
4. write the current time into the BIOS for permanent effect (to prevent failure after restart)

# Hwclock

Generally, two methods are used to obtain the timestamp in the inux shell. one is to directly call the system variable; the other is to obtain the timestamp using a pure shell script. The example is as follows:

1. directly call system variables

Obtain the current period: date + % Y % m % d' or date + % F

Get the period of yesterday: 'Date-d yesterday + % Y % m % d'

Get date of the day before yesterday: 'Date-d-2day + % Y % m % d'

And so on, for example, get the date 10 days ago: 'Date-d-10day + % Y % m % d'

Note that there are spaces in the middle.

2. implement it by using shell. the following example shows the shell that calculates the date of yesterday when the current day is known.

Startdate = 'Date'
D1 = 'Date' + % Y % m % d''
If test! "$1" = ""
Then
D1 = $1
Fi
Echo "today is ${d1 }"
Yesterday ()
{
YEAR = 'expr substr "$ {d1}" 1 4'
MONTH = 'expr substr "$ {d1}" 5 2'
DAY = 'expr substr "$ {d1}" 7 2'
If [$ DAY-eq 1]
Then
If [$ MONTH-eq 1]
Then
YEAR = 'expr $ YEAR-1'
MONTH = 12
Else
MONTH = 'expr $ MONTH-1'
Fi
DAY = 'echo \ 'Cal $ MONTH $ YEAR \ '| tail-n1 | awk' {print $ NF }''
Else
DAY = 'expr $ DAY-1'
Fi
D2 = 'echo "$ YEAR $ MONTH $ DAY" | awk '{if (length ($2) = 1) $2 = 0 $2; if (length ($3) = 1) $3 = 0 $3; printf "% s", $1, $2, $3 }''
}
Yesterday
Echo "yesterday IS ${d2 }"



Author: jsczxy2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.