加载中…
个人资料
pzghost
pzghost
  • 博客等级:
  • 博客积分:0
  • 博客访问:36,843
  • 关注人气:5
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
相关博文
推荐博文
谁看过这篇博文
加载中…
正文 字体大小:

Linux 时间设置

(2011-03-10 11:50:14)
标签:

南澳大利亚

系统时钟

设置

h2

硬件

it

分类: linux

 

转自http://translate.google.com.hk/translate?hl=zh-CN&langpair=en|zh-CN&u=http://www.linuxsa.org.au/tips/time.html

简介

This document explains how to set your computer's clock from Linux, how to set your timezone, and other stuff related to Linux and how it does its time-keeping.本文档介绍了如何设置计算机的时钟从Linux,如何设置时区,以及其他相关的东西到Linux和它的时间它是如何维持。

Your computer has two timepieces; a battery-backed one that is always running (the ``hardware'', ``BIOS'', or ``CMOS'' clock), and another that is maintained by the operating system currently running on your computer (the ``system'' clock).您的计算机有两个时钟,一个电池供电的一个是始终运行(``硬件'',``的BIOS '',或`` ''的CMOS时钟),另一个是由操作系统维护当前正在运行您的计算机('' ``系统时钟)。 The hardware clock is generally only used to set the system clock when your operating system boots, and then from that point until you reboot or turn off your system, the system clock is the one used to keep track of time.硬件时钟通常只用于设置当您的操作系统启动,然后从该点系统时钟直到重启或关闭系统,该系统时钟来记录时间的之一。

On Linux systems, you have a choice of keeping the hardware clock in UTC/GMT time or local time.在Linux系统中,你有一个用UTC / GMT时间或本地时间来记录硬件时钟。 The preferred option is to keep it in UTC because then daylight savings can be automatically accounted for.推荐的选项是用UTC记录,因为夏令时可以自动记录。 The only disadvantage with keeping the hardware clock in UTC is that if you dual boot with an operating system (such as DOS) that expects the hardware clock to be set to local time, the time will always be wrong in that operating system.用UTC记录硬件时钟的唯一缺点是,如果你的操作系统(如DOS)要求硬件时钟用本地时间设置双重启动,时间总是在那个操作系统错误的。

Setting your timezone设置时区

The timezone under Linux is set by a symbolic link from /etc/localtime [1] to a file in the /usr/share/zoneinfo [2] directory that corresponds with what timezone you are in. For example, since I'm in South Australia, /etc/localtime is a symlink to /usr/share/zoneinfo/Australia/South . Linux的时区是由下一个符号链接从/etc/localtime [1]文件在向/usr/share/zoneinfo [2]目录,例如对应您所在时区为所在,因为我在南澳大利亚, /etc/localtime是一个符号链接/usr/share/zoneinfo/Australia/South To set this link, type:要设置此链接,请键入:

ln -sf ../usr/share/zoneinfo/ your/zone /etc/localtime

Replace your/zone with something like Australia/NSW or Australia/Perth .替换your/zone喜欢的事与Australia/NSWAustralia/Perth Have a look in the directories under /usr/share/zoneinfo to see what timezones are available.有一个看的目录下/usr/share/zoneinfo看到什么时区。

[1] This assumes that /usr/share/zoneinfo is linked to /etc/localtime as it is under Red Hat Linux. [1]这里假设/usr/share/zoneinfo链接到/etc/localtime ,因为Linux是红帽。

[2] On older systems, you'll find that /usr/lib/zoneinfo is used instead of /usr/share/zoneinfo . [2]在旧版本的系统,你会发现/usr/lib/zoneinfo是用来代替/usr/share/zoneinfo See also the later section `` The time in some applications is wrong ''. 另见后面的章节`` 中的应用有些是错误的时间 ''。

Setting UTC or local time设置UTC或本地时间

When Linux boots, one of the initialisation scripts will run the /sbin/hwclock program to copy the current hardware clock time to the system clock. hwclock will assume the hardware clock is set to local time unless it is run with the --utc switch.当Linux启动时初始化脚本之一,将运行/sbin/hwclock程序复制当前硬件时钟时间到系统时钟。 hwclock假定硬件时钟设置为本地时间,除非它的运行--utc开关。 Rather than editing the startup script, under Red Hat Linux you should edit the /etc/sysconfig/clock file and change the `` UTC '' line to either ``UTC=true'' or ``UTC=false'' as appropriate.而不是编辑启动脚本Linux中,红帽,你应该编辑/etc/sysconfig/clock文件,并改变`` UTC ''线要么``真''或联合技术= = `` Utc的适当假'' 。

Setting the system clock设置系统时钟

To set the system clock under Linux, use the date command. Linux下设置系统时钟,使用date命令。 As an example, to set the current time and date to July 31, 11:16pm, type `` date 07312316 '' (note that the time is given in 24 hour notation).作为一个例子,设置当前时间和日期为7月31日下午11时十六,键入`` date 07312316 ''(请注意,时间是24小时表示法中给出)。 If you wanted to change the year as well, you could type `` date 073123161998 ''.如果你想改变一年好,你可以键入`` date 073123161998 ''。 To set the seconds as well, type `` date 07312316.30 '' or `` date 073123161998.30 ''.要设置的类型以及``秒, date 07312316.30 ''或`` date 073123161998.30 ''。 To see what Linux thinks the current local time is, run date with no arguments.要查看Linux当前本地时间,使用date ,不带参数。

Setting the hardware clock设置硬件时钟

To set the hardware clock, my favourite way is to set the system clock first, and then set the hardware clock to the current system clock by typing `` /sbin/hwclock --systohc '' (or `` /sbin/hwclock --systohc --utc '' if you are keeping the hardware clock in UTC).要设置硬件时钟,我喜欢的方式是首先设置系统时钟,然后设置为当前系统时钟硬件时钟输入`` /sbin/hwclock --systohc ''(或`` /sbin/hwclock --systohc --utc ''如果您把时钟UTC记录硬件)。 To see what the hardware clock is currently set to, run hwclock with no arguments.要查看当前硬件时钟的设置,运行hwclock不带参数。 If the hardware clock is in UTC and you want to see the local equivalent, type `` /sbin/hwclock --utc ''如果硬件时钟是UTC与你想看相应的本地键入`` /sbin/hwclock --utc ''

The time in some applications is wrong 在某些时候的应用程序是错误的

If some applications (such as date ) display the correct time, but others don't, and you are running Red Hat Linux 5.0 or 5.1, you most likely have run into a bug caused by a move of the timezone information from /usr/lib/zoneinfo to /usr/share/zoneinfo .如果某些应用程序(如date )显示正确的时间,但其他人不这样做,而你运行的是红帽Linux 5.0或5.1中,你最有可能遇到了一个错误信息造成的时区由移动/usr/lib/zoneinfo/usr/share/zoneinfo The fix is to create a symbolic link from /usr/lib/zoneinfo to /usr/share/zoneinfo : `` ln -s ../share/zoneinfo /usr/lib/zoneinfo ''.解决方法是建立一个链接,从象征性的/usr/lib/zoneinfo/usr/share/zoneinfo :`` ln -s ../share/zoneinfo /usr/lib/zoneinfo ''。

Summary综述

  • /etc/sysconfig/clock sets whether the hardware clock is stored as UTC or local time. /etc/sysconfig/clock的时间设置硬件时钟,无论本地存储为UTC或。

     

  • Symlink /etc/localtime to /usr/share/zoneinfo/... to set your timezone.符号链接/etc/localtime/usr/share/zoneinfo/...设置你的时区。

     

  • Run `` date MMDDhhmm '' to set the current system date/time.运行`` date MMDDhhmm ''来设置当前系统日期/时间。

     

  • Type `` /sbin/hwclock --systohc [--utc] '' to set the hardware clock.键入`` /sbin/hwclock --systohc [--utc] ''来设置硬件时钟。

     

Other interesting notes其他有趣的注解:

The Linux kernel always stores and calculates time as the number of seconds since midnight of the 1st of January 1970 UTC regardless of whether your hardware clock is stored as UTC or not. Linux内核一直以来,储存和计算UTC 1972年一月一日午夜无论您的硬件时钟是UTC保存的时间的秒数。 Conversions to your local time are done at run-time.到本地时间转换的工作是运行时间。 One neat thing about this is that if someone is using your computer from a different timezone, they can set the TZ environment variable and all dates and times will appear correct for their timezone.一个关于这个整洁的是,如果有人正在使用不同的时区从您的计算机,他可以设置TZ环境变量,所有的日期和时间将出现的时区正确。

If the number of seconds since the 1st of January 1970 UTC is stored as an signed 32-bit integer (as it is on your Linux/Intel system), your clock will stop working sometime on the year 2038.如果秒自1970年1月的UTC是作为符号的32位整数存储的第一号(因为它在你的Linux / Intel系统上),您的时钟将停止工作在2038年的某个时候。 Linux has no inherent Y2K problem, but it does have a year 2038 problem. Linux没有Y2K问题,但它确实有一个2038年的问题。 Hopefully we'll all be running Linux on 64-bit systems by then.希望我们都将运行在64位系统,那么Linux。 64-bit integers will keep our clocks running quite well until aproximately the year 292271-million. 64位整数将继续,直到大约一年292271万我们的时钟运行得非常好。

Other programs worth looking at值得关注的其他方案

  • rdate - get the current time from a remote machine; can be used to set the system time. rdate -获取远程机器获得当前时间从一,可以用来设置系统时间。

     

  • xntpd - like rdate , but it's extremely accurate and you need a permanent 'net connection. xntpd runs continuously and accounts for things like network delay and clock drift, but there's also a program ( ntpdate ) included that just sets the current time like rdate does. xntpd -像rdate ,但它非常准确,你需要一个永久的网络连接。 xntpd持续地运行,占漂移事情,比如网络延时,时钟,但是也有一个程序( ntpdate )包括在内,只设置类似rdata当前时间不。

     

Further information进一步资料

  • date(1)

     

  • hwclock(8)

     

  • /usr/doc/HOWTO/mini/Clock

0

阅读 评论 收藏 转载 喜欢 打印举报/Report
  • 评论加载中,请稍候...
发评论

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 电话:4000520066 提示音后按1键(按当地市话标准计费) 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有