Linux如何修改和查询时区时间

  我在日常工作中,最近遇到了在解压源码包的时候,提示时间比较旧,解压安装出现问题。原因是,租用的vps所在时区和自己所需要的时区不一致,于是在网上找了相关资料。并亲自实践,将其记录如下,以供日后方便使用。

一、时区

参考资料:http://www.cnblogs.com/h2appy/archive/2008/11/27/1342029.html

# 当前操作系统版本

[root@erwtd ~]# cat /etc/redhat-release

CentOS release 6.9 (Final)

# 1、查看当前时区:东9区

[root@erwtd ~]# date -R

Mon,  Dec  :: +

[root@erwtd ~]# 

# 2、修改时区

[root@erwtd ~]# tzselect

Please identify a location so that time zone rules can be set correctly.

Please select a continent or ocean.

 ) Africa

 ) Americas

 ) Antarctica

 ) Arctic Ocean

 ) Asia

 ) Atlantic Ocean

 ) Australia

 ) Europe

 ) Indian Ocean

) Pacific Ocean

) none - I want to specify the time zone using the Posix TZ format.

#? 

Please select a country.

 ) Afghanistan           ) Israel                ) Palestine

 ) Armenia               ) Japan                 ) Philippines

 ) Azerbaijan            ) Jordan                ) Qatar

 ) Bahrain               ) Kazakhstan            ) Russia

 ) Bangladesh            ) Korea (North)         ) Saudi Arabia

 ) Bhutan                ) Korea (South)         ) Singapore

 ) Brunei                ) Kuwait                ) Sri Lanka

 ) Cambodia              ) Kyrgyzstan            ) Syria

 ) China                 ) Laos                  ) Taiwan

) Cyprus                ) Lebanon               ) Tajikistan

) East Timor            ) Macau                 ) Thailand

) Georgia               ) Malaysia              ) Turkmenistan

) Hong Kong             ) Mongolia              ) United Arab Emirates

) India                 ) Myanmar (Burma)       ) Uzbekistan

) Indonesia             ) Nepal                 ) Vietnam

) Iran                  ) Oman                  ) Yemen

) Iraq                  ) Pakistan

#? 

Please select one of the following time zone regions.

) Beijing Time

) Xinjiang Time

#? 

The following information has been given:

        China

        Beijing Time

Therefore TZ='Asia/Shanghai' will be used.

Local time is now:      Mon Dec  :: CST .

Universal Time is now:  Mon Dec  :: UTC .

Is the above information OK?

) Yes

) No

#? 

You can make this change permanent for yourself by appending the line

        TZ='Asia/Shanghai'; export TZ

to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you

can use the /usr/bin/tzselect command in shell scripts:

Asia/Shanghai

[root@erwtd ~]# 

#3、复制相应的时区文件,替换系统时区文件

# cp /usr/share/zoneinfo/$主时区/$次时区 /etc/localtime

#在中国可以使用:

[root@erwtd ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 

一、时间

#1、查看当前时间

[root@erwtd ~]# date

Mon Dec  :: CST 

[root@erwtd ~]#

#2、设置时间和日期

[root@erwtd ~]# date -s "20171211 11:29:30"
Mon Dec :: CST
[root@erwtd ~]#
#或者单独修改时间
[root@erwtd ~]# date -s
Wed Dec :: CST
[root@erwtd ~]# date -s ::
Wed Dec :: CST
[root@erwtd ~]# date
Wed Dec :: CST
[root@erwtd ~]#

#3、保存设置

[root@erwtd ~]# hwclock  -w

二、时间同步shell脚本

[root@erwtd ~]#cat /root/ntp.sh
#!/bin/bash
# ntp.sh
#NTP服务器数组列表
ntpServer=(
[]=.cn.pool.ntp.org
[]=.cn.pool.ntp.org
[]=.cn.pool.ntp.org
[]=.cn.pool.ntp.org
) #校验#
serverNum=
NUM=
for ((i=; i<=$serverNum; i++)); do
echo -n "正在和NTP服务器:${ntpServer[$NUM]}校验中..."
/usr/sbin/ntpdate ${ntpServer[$NUM]} >> /dev/null >&
if [ $? -eq ]; then
echo -e "\e[1;32m\t[成功]\e[0m"
echo -e "\e[1;32m同步成功,退出......\e[0m"
break
else
echo -e "\e[1;31m\t[失败]\e[0m"
echo -e "\e[1;31m继续同步下一个!!!!!\e[0m"
let NUM++
fi
sleep
done
[root@erwtd ~]#
[root@erwtd ~]# sh /root/ntp.sh
正在和NTP服务器:tw.pool.ntp.org校验中... [成功]
同步成功,退出......
[root@erwtd ~]#

Linux如何修改和查询时区时间的更多相关文章

  1. 【Linux基础】linux下修改ls显示的时间格式

    1.修改ls显示格式 ls -l --time-style '+%Y/%m/%d %H:%M:%S' drwxr-x--- edwetl edwetl // :: arc_test ls -l --t ...

  2. docker修改容器gogs时区时间

    问题描述: 公司内部搭建了一个gogs-git,是用docker部署的,但是发现提交的代码什么的时间跟服务器时间不一致 提交上去的世界是UTC时间不是中国的时间CST,相当于慢了8个小时 1.dock ...

  3. Linux学习 - 修改、查询文件内容

    一.显示文件内容 cat  [-n]  [文件名] 正向显示 -n 显示行号 tac  [文件名] 反向显示 more  [文件名] 可实现分页显示 (空格)或(f) 翻页 (Enter) 换行 (q ...

  4. linux系统修改系统时间与时区

    有装过Linux系统的人,可能都会有这样的经历,就是该机器安装windows系统时,时间正确,但是安装了linux系统后,尽管时区选择正确,也会发现系统时间不对.这是由于安装系统时采用了UTC,那么什 ...

  5. Linux下修改时间时区的方法介绍

    点评:在Linux中,用于时钟查看和设置的命令主要有date.hwclock和clock.其中,clock和 hwclock用法相近,只不过clock命令除了支持x86硬件体系外,还支持Alpha硬件 ...

  6. linux系统修改CST时区

    ================================================= [root@tzyyserveryg ~]# date -R Fri, 28 Nov 2014 08 ...

  7. Linux怎样修改系统时间

    修改linux的时间可以使用date指令 修改日期: 时间设定成2009年5月10日的命令如下: #date -s 05/10/2009 修改时间: 将系统时间设定成上午10点18分0秒的命令如下. ...

  8. Linux 服务器修改时间与时间同步

    设置时间 date --set '2015-11-23 0:10:40' # 方法一,通用 timedatectl set-time '2015-11-23 08:10:40' # 容器内可能不支持 ...

  9. Linux环境变量的修改(永久,暂时)以及修改ls显示的时间格式

    本文转自:http://blog.sina.com.cn/s/blog_8e21864f01014u9h.html Linux修改环境变量,很简单但很重要 一.Linux的变量种类 按变量的生存周期来 ...

随机推荐

  1. SQL Server For XML

    FOR XML PATH 有的人可能知道有的人可能不知道,其实它就是将查询结果集以XML形式展现,有了它我们可以简化我们的查询语句实现一些以前可能需要借助函数活存储过程来完成的工作.那么以一个实例为主 ...

  2. 小程序——Tab切换

    <view class="body"> <view class="nav bc_white"> <view class=" ...

  3. 基本排序算法[python实现]

    冒泡排序 原理 冒泡排序(Bubble Sort)是一种简单的排序算法.它重复地走访过要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来.走访数列的工作是重复地进行直到没有再需要交换, ...

  4. kubernetes job的原理

    job例子: apiVersion: batch/v1 #job的apiVersion kind: Job #资源类型为job metadata: labels: name: busybox name ...

  5. Dijkstra—校园景点游览问题

    #include<iostream> #include<cstdio> #include<cstring> #define MAX 9999999 using na ...

  6. 查询SQL磁盘活动量信息

    /* 用来显示有关由 Transact-SQL 语句生成的磁盘活动量的信息.*/DBCC DROPCLEANBUFFERS --清空缓存set statistics io on --开启set sta ...

  7. 基准对象object中的基础类型----字典 (六)

    object有如下子类: CLASSES object basestring str unicode buffer bytearray classmethod complex dict enumera ...

  8. The Unique MST POJ - 1679 次小生成树prim

    求次小生成树思路: 先把最小生成树求出来  用一个Max[i][j] 数组把  i点到j 点的道路中 权值最大的那个记录下来 used数组记录该条边有没有被最小生成树使用过   把没有使用过的一条边加 ...

  9. bzoj 3631 松鼠的新家 (树链剖分)

    链接: https://www.lydsy.com/JudgeOnline/problem.php?id=3631 思路: 直接用树链剖分求每一次运动,因为这道题只需要区间增添,单点求值,没必要用线段 ...

  10. HihoCoder 1511: 树的方差(prufer序)

    题意 对于一棵 \(n\) 个点的带标号无根树,设 \(d[i]\) 为点 \(i\) 的度数,定义一棵树的方差为数组 \(d[1..n]\) 的方差. 给定 \(n\) ,求所有带标号的 \(n\) ...