The Linux timestamp and the standard time of the mutual turn

Source: Internet
Author: User

In Linux systems, there are many occasions where timestamps are used to represent time, that is, the number of days or seconds from January 1, 1970 onwards. such as the password change date and expiration date in/etc/shadow, as well as the access log of the proxy server to record the access time and so on.

Here are some methods of timestamp format and standard Time format conversion:

1. Display the current time in standard format and time stamp, respectively
[[Email protected] ~]# Date
August 10, 2010 Tuesday 03:39:21 CST

[Email protected] ~]# date +%s
1281382775

2. Display time stamp of specified time
[Email protected] ~]# date-d "2010-07-20 10:25:30" +%s
1279592730



3. Convert timestamp to Standard time format

Method 1: Use the date command

[Email protected] ~]# date-d "@1279592730"
July 20, 2010 Tuesday 10:25:30 CST
[[email protected] ~]# date-d "1970-01-01 UTC 1279592730 Seconds"
July 20, 2010 Tuesday 10:25:30 CST
[Email protected] ~]# date-d "1970-01-01 14781 Days" "+%y/%m/%d%h:%m:%s"
2010/06/21 00:00:00
[Email protected] tmp]# date-d "@1279592730"
Tue Jul 10:25:30 CST 2010
[Email protected] tmp]# date-d "@1279592730" + "%y%m%d%h:%m:%s"
20100720 10:25:30
[Email protected] tmp]# date-d "@1279592730" + "%F%h:%m:%s"
2010-07-20 10:25:30
[[email protected] tmp]# date-d "1970-01-01 UTC 1279592730 Seconds"
Tue Jul 10:25:30 CST 2010
[[email protected] tmp]# date-d "1970-01-01 UTC 1279592730 Seconds" + "%F%h:%m:%s" 2010-07-20 10:25:30

Method 2: Use the time function in awk

[[email protected] ~]# echo "1279592730" |awk ' {print strftime ("%F%T", $)} '
2010-07-20 10:25:30

Method 3: Use Perl to process

[Email protected] ~]# perl-e ' Print localtime (1279592730). " \ n ";"
Tue Jul 20 10:25:30 2010

Add:

About the interpretation of the time format

UTC (Universal time COORDINATED,UTC) world coordination Times

CST China Time utc+8:00 (Beijing time)

GMT (Greenwich Mean Time) GMT:

System Time zone settings:

[Email protected] ~]# vim/etc/sysconfig/clock zone= "Asia/shanghai"
Utc=true
Arc=false
[Email protected] ~]# Cp/usr/share/zoneinfo/asia/shanghai/etc/localtime
--------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------

Convert Unix/linux timestamps in Oracle

The Unix/linux timestamp is a number of seconds calculated from the GMT January 1, 1970 period.

Unix/linux timestamp converted to standard time format (mainly note time zone issues):

Select To_date (' 19700101 ', ' yyyymmdd ') + 1235728935/86400 +to_number (SUBSTR (Tz_offset), Sessiontimezone)) 1,3 from Dual 1235728935 is Unix/linux time stamp, after conversion is expressed as 2009-2-27 18:02:15.

In turn, the time zone is also considered:

Select (To_date (' 2009-2-27 18:02:15 ', ' yyyy-mm-dd hh24:mi:ss ')-to_date (' 1970-1-1 ', ' yyyy-mm-dd ')) *86400-to_number ( SUBSTR (Tz_offset (Sessiontimezone), 1,3)) *3600 from dual


This article is from the "Dream to Reality" blog, please be sure to keep this source http://lookingdream.blog.51cto.com/5177800/1846493

The Linux timestamp and the standard time of the mutual turn

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.