Get the App
SLTechnology News&Howtos  ›  Servers  › 

Linux shell downconversion unix time

Shulou Source: shulou.com Published: 2022-06-02 23:38:41 10月05日 Update

Linux shell downconversion unix time

Here is a little way to convert the Unix time display format under Shell, and give a solution to the students who are familiar with the date command immediately.

$date-d @ 1234567890

Sat Feb 14 07:31:30 CST 2009

But what if the date version is too low to support the @ parameter? Let's try the-d parameter

$date-d "UTC 1970-01-01 1234567890 secs"

Sat Feb 14 07:31:30 CST 2009

If you think you can't remember a long string of characters at a time, write a small function yourself, which you can call in ~ / .bashrc.

# convert Unix time to local time string

Function ctime ()

{

Date-d "UTC 1970-01-01 $1 secs"

}

How to use it is simple:

$ctime 1234567890

Sat Feb 14 07:31:30 CST 2009

[this article was first posted in: Baidu Operation and maintenance Space] http://hi.baidu.com/ops_bd/blog/item/a3cca26712209058eaf8f87b.html

[pay attention to Baidu Technology Salon]

Tags: Time method parameter character usage function classmate reunion command string what to do technology format salon version dimension support input Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Tech Info NVidia Shulou Technology macOS