Date用法(转)
linux下对date和timestamp的互转
1. date 到 timestamp:
$ date -d '2009-12-01 23:20'
%s
1259680800
2. timestamp 到
date
$ date -d '1970-01-01 1259680800 sec
utc'
Tue Dec 1 23:20:00 CST
2009
3. timestamp 到 UTC date
[root@CDM ~]# date -d '1970-01-01 UTC 1284117137
sec' -u
五 9月 10 11:12:17 UTC 2010
4. date,当前时间转换为UTC
timestamp
[root@CDM ~]#
date +%s
1284117146
美国夏季始于每年4月的第1个周日,止于每年10月的最后一个周日。夏令时比正常时间早一小时,与PDT时间相对应的是PST , Pacific Standard Time 。 夏时制结束后就是PST
- NST - Newfoundland Standard Time 纽芬兰标准时间
- NDT - Newfoundland Daylight Time 纽芬兰夏令时间
- AST - Atlantic Standard Time 大西洋标准时间
- ADT - Atlantic Daylight Time 大西洋夏令时间
- EST - Eastern Standard Time 东部标准时间
- EDT - Eastern Daylight Time 东部夏令时间
- CST - Central Standard Time 中部标准时间
- CDT - Central Daylight Time 中部夏令时间
- MST - Mountain Standard Time 山地标准时间
- MDT - Mountain Daylight Time 山地夏令时间
- PST - Pacific Standard Time 太平洋标准时间
- PDT - Pacific Daylight Time 太平洋夏令时间
- AKST - Alaska Standard Time 阿拉斯加标准时间
- AKDT - Alaska Daylight Time 阿拉斯加夏令时间
- HAST - Hawaii-Aleutian Standard Time 夏威夷-阿留申标准时间
- HADT - Hawaii-Aleutian Daylight Time 夏威夷-阿留申夏令时间
PST
PST是太平洋标准时间(西八区),与北京时间(东八区)时差-16个小时,也就是北京时间减去16就是PST时间。而PDT比PST早1个小时,就是说PDT与北京时间时差为-15小时
夏令时
但是根据美国国会最 新通过的能源法案,为加强日光节约,自2007年起延长夏令时间,开始日期从每年4月的第一个星期日,提前到3月的第二个星期日,结束日期从每年10月的 最后一个星期日,延后到11月的第一个星期日。换言之,冬令时间将缩短约一个月。之所以安排在周日,是为了便于生活的调整不至于受到较大的影响。
Linux下修改时间时区
Linux时钟分为系统时钟(System Clock)和硬件(Real Time Clock,简称RTC)时钟。系统时钟是指当前Linux Kernel中的时钟,而硬件时钟则是主板上由电池供电的时钟,这个硬件时钟可以在BIOS中进行设置。当Linux启动时,硬件时钟会去读取系统时钟的设置,然后系统时钟就会独立于硬件运作。
Local vs. UTC
首先重要的问题是你使用utc还是local time. UTC(Universal Time Coordinated)=GMT(Greenwich Mean Time) Local time 是你手表上的时间 传统的POSIX计算机(Solaris,bsd,unix)使用UTC格式 linux可以处理UTC时间和蹩脚的Windows所使用的local time 到底是使用UTC还是local time可以这样来确定: 如果机器上同时安装有Linux和Windows,建议使用local time 如果机器上只安装有Linux,建议使用utc 确定后编辑/etc/sysconfig/clock, UTC=0 是local time; UTC=1 是UTC(GMT) 确定timezone 运行tzselect,回答问题后会告诉你时区的名称,比如"Asia/Shanghai",把他记下来(后面我用$timezone代替) 设定timezone # cp /usr/share/zoneinfo/$timezone /etc/localtime 重新启动或者运行时钟设置脚本使之发生作用 版本差异 由于发行版的差异,以上文件位置可能不同。 一般设置时钟所使用的启动脚本为/etc/rc.d/init.d/setclock redhat是在/etc/rc.d/rc.sysinit中设置时钟,所以一般要重新启动 |
- FROM_UNIXTIME(unix_timestamp) , FROM_UNIXTIME(unix_timestamp,format)
返回'YYYY-MM-DD HH:MM:SS'或YYYYMMDDHHMMSS 格式值的unix_timestamp参数表示,
将UTC时间戳转换为本地时区时间格式
http://blog.sina.com.cn/s/blog_5482553a0100l6s8.html
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Next: arch invocation, Up: System context
21.1date: Print or set system date and time
date [option]... [+format]
date [-u|--utc|--universal]
[ MMDDhhmm[[CC]YY][.ss] ]
Invokingdatewith no formatargument is equivalent to invoking it with a default format that depends on theLC_TIMElocale category. In the default C locale, this format is ‘'+%a %b %e %H:%M:%S %Z %Y'’, so the output looks like ‘Thu Mar 3 13:47:51 PST 2005’.
Normally,dateuses the time zone rules indicated by theTZenvironment variable, or the system default rules ifTZis not set. See Specifying the Time Zone withTZ.
If given an argument that starts with a ‘+’,dateprints the current date and time (or the date and time specified by the--dateoption, see below) in the format defined by that argument, which is similar to that of the strftime
function. Except for conversion specifiers, which start with ‘%’, characters in the format string are printed unchanged. The conversion specifiers are described below.
An exit status of zero indicates success, and a nonzero value indicates failure.
http://www.gnu.org/software/coreutils/manual/html_node/date-invocation.html#date-invocation