Commands for interchange of date, time, and Unix timestamps in Linux Command lines

Source: Internet
Author: User

Commands for interchange of date, time, and Unix timestamps in Linux Command lines

At work, you often need to get the current Unix timestamp or convert the given timestamp to a date format that we can recognize, on the linux Command Line terminal, you can easily solve the problem by using several commands.

1. convert a date to a Unix Timestamp

(1) present the current time in Unix timestamp:

Date + % s

The output is as follows:

1361542433

(2) convert the specified date to the Unix timestamp:

Date-d '2017-2-22 '+ % s

The output is as follows:

1361542440

2. Convert Unix timestamp to datetime

(1) do not specify the date and time format:

Date-d @ 1361542596

The output is as follows:

Fri Feb 22 12 22:16:36 CST 2013

(2) Date Format Conversion:

Date-d @ 1361542596 + "% Y-% m-% d % H: % M: % S"

The output is as follows:

2013-02-22 22:16:36

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.