[Linux] conversion between the date command Timestamp and time

Source: Internet
Author: User

[Linux] conversion between the date command Timestamp and time

Most of the time we view the data in the database, or some data in other systems needs to be queried using timestamps, or the query results are timestamps. In addition, you must enter a timestamp for the query condition. My previous method was to use an online tool, and then I used a mac. I thought it would be nice to use a command line to solve the problem, you don't need to open a browser every time (in fact, it is also troublesome to be unfamiliar with the command)

Here is the operation in mac, mainly using the date command. For more usage, use the man command to view

String format time TO Timestamp

We know that the date command can directly convert the current time to the timestamp.

# date +%s1436781527

Then, we will convert the defined time to the timestamp.

# date -j -f "%Y-%m-%d %H:%M:%S" "2015-07-13 18:02:00" "+%s"1436781720

In fact, this is a little complicated.

Timestamp to time

However, it is easy to convert the timestamp into a readable time format. mac and centos are slightly different.

Mac

Date-r1436781720 Monday July 13, 2015 seconds CST

On centos

$ Date-d @ 14367817202015 Monday, January 1, July 13 18:02:00 CST

These two commands are really easy to remember.

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.