linux标准时间和时间戳的转换
来源:互联网 发布:局域网内部监控软件 编辑:程序博客网 时间:2024/05/16 15:43
在LINUX系统中,有许多场合都使用时间戳的方式表示时间,即从1970年1月1日起至当前的天数或秒数。如/etc/shadow里的密码更改日期和失效日期,还有代理服务器的访问日志对访问时间的记录等等。
下面介绍几种时间戳格式和标准时间格式转换的方法:
1、分别以标准格式和时间戳来显示当前时间
[root@365linux ~]# date
2010年 08月 10日 星期二 03:39:21 CST
[root@365linux ~]# date +%s 1281382775
2、显示指定时间的时间戳
[root@365linux ~]# date -d "2010-07-20 10:25:30" +%s
1279592730
3、将时间戳转换为标准时间格式
方法1:使用date命令
[root@365linux ~]# date -d "@1279592730"
2010年 07月 20日 星期二 10:25:30 CST
[root@365linux ~]# date -d "1970-01-01 utc 1279592730 seconds"
2010年 07月 20日 星期二 10:25:30 CST
[root@365linux ~]# date -d "1970-01-01 14781 days" "+%Y/%m/%d %H:%M:%S"
2010/06/21 00:00:00
[root@localhost tmp]# date -d "@1279592730"
Tue Jul 20 10:25:30 CST 2010
[root@localhost tmp]# date -d "@1279592730" +"%Y%m%d %H:%M:%S"
20100720 10:25:30
[root@localhost tmp]# date -d "@1279592730" +"%F %H:%M:%S"
2010-07-20 10:25:30
[root@localhost tmp]# date -d "1970-01-01 utc 1279592730 seconds"
Tue Jul 20 10:25:30 CST 2010
[root@localhost tmp]# date -d "1970-01-01 utc 1279592730 seconds" +"%F %H:%M:%S"
2010-07-20 10:25:30
方法2:使用awk里的时间函数
[root@365linux ~]# echo "1279592730" |awk '{print strftime ("%F %T",$0)}'
2010-07-20 10:25:30
方法3:使用perl处理
[root@365linux ~]# perl -e 'print localtime(1279592730)."\n";'
Tue Jul 20 10:25:30 2010
补充:
关于时间格式的解释
UTC (Universal Time Coordinated,UTC)世界协调时间
CST (China Standard Time UTC+8:00)中国沿海时间(北京时间)
GMT (Greenwich Mean Time)格林威治标准时间:
- linux标准时间和时间戳的转换
- Linux时间戳 与 标准时间 转换
- 时间戳和标准时间转换
- ios标准时间和时间戳的转换
- iOS 时间戳和标准时间的转换
- Linux下时间戳格式和标准时间格式的转换
- Linux下时间戳格式和标准时间格式的转换
- Linux下时间戳格式和标准时间格式的转换
- Linux下时间戳格式和标准时间格式的转换
- Linux 时间戳和标准时间
- Linux时间戳和标准时间的互转
- Linux时间戳和标准时间的互转【转】
- Linux时间戳和标准时间的互转
- Linux时间戳和标准时间的互转
- Linux时间戳和标准时间的互转-zz
- Linux时间戳和标准时间的互转
- Linux时间戳和标准时间的互转
- Linux时间戳和标准时间的互转
- this.ds错误
- java 正常的线程停止操作思想
- missing field - fillRecord not enabled 错误信息
- Win7配置驱动开发环境(wdk7.60)
- C++多线程4互锁函数
- linux标准时间和时间戳的转换
- c++线程学习5等待函数
- VS2008 、WDK 和DDKWizard搭建Win7驱动开发环境
- 创建桌面快捷方式
- iOS之KVC和KVO
- ios多线程开发——nsoperation详解
- 沉淀浮躁的心吧 送给刚毕业的我们
- [DFS] cf 134A Ice Skating
- C++多线程(6)对象互斥