zoukankan      html  css  js  c++  java
  • Linux系统更改时区

    更改时区

    在给国外伙伴部署机器的时候,经常会碰到需要给Linux修改时区的情况:

    这里例举几个方式:

    1:覆盖/etc/localtime文件内容

    /usr/share/zoneinfo/ 下面都是对应的洲以及其对应的时区,如果我们需要修改时区为Shanghai的话,执行下面的操作:

    [root@VM-75-60 ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    cp: overwrite `/etc/localtime'? y
    [root@VM-75-60 ~]#

    检测是否生效:

    [root@VM-75-60 ~]# date -R
    Fri, 24 Jul 2020 22:59:39 +0800

    最后的参数‘+0800’就表示东八区!

    2:tzselect指令

    [root@VM-75-60 ~]# tzselect
    Please identify a location so that time zone rules can be set correctly.
    Please select a continent or ocean.
     1) Africa
     2) Americas
     3) Antarctica
     4) Arctic Ocean
     5) Asia
     6) Atlantic Ocean
     7) Australia
     8) Europe
     9) Indian Ocean
    10) Pacific Ocean
    11) none - I want to specify the time zone using the Posix TZ format.

    通过交互式,利用首位的数字去选择你想要选择的时区。

    但这里tzselect并不能真正设置当前机器的时区,他只是一个向导,让你找到你想要找到的地区时区表示方式以及如何让它生效,指令在最后给出了:

    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.

    你看,他让你编辑.profile,设置个TZ变量。。。

    第一种方法直接cp覆盖不香吗?

    注意:升级了glibc之后的机器,crond和rsyslog等程序的读取时间都会变成新的glibc下的localtime,因此需要重新做软连接,把/etc/localtime软连接到新的glibc下的localtime

  • 相关阅读:
    持续集成(Continuous Integration),
    python的几个有趣点
    C++语言发展历史 & 基础知识
    [C++] Windows下的socket编程(这是一个简单的TCP/IP例子)
    office app 代码简析之 task pane app
    佳言玩具
    数据的图形可视化[R语言结果GML引发出来的调查]
    收藏的一系列教程帖子,很适合有一定基础,想要进阶的同学
    各种排序算法总结
    三层架构+存储过程实现分页
  • 原文地址:https://www.cnblogs.com/storyawine/p/13357729.html
Copyright © 2011-2022 走看看