📜  unix timestamp bash - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:48:13.439000             🧑  作者: Mango

Unix Timestamp in Bash Shell

Unix timestamp is a way of representing the current time as a number of seconds since January 1, 1970 midnight UTC. This system is used widely in computer systems to represent and manipulate time.

Getting Unix Timestamp in Bash Shell

In Bash shell, we can use the date command to get the Unix timestamp. The command to get the Unix timestamp is:

date +%s

Here, the %s option in the date command tells it to output the number of seconds since January 1, 1970 midnight UTC.

Converting Unix Timestamp to Human Readable Time

To convert the Unix timestamp to human readable time, we can use the date command again. The command to convert the Unix timestamp to human readable time is:

date -d @<timestamp>

Here, the -d option tells the date command to use the given timestamp as the input. The @ symbol before the timestamp tells the date command that the input is in Unix timestamp format.

For example, to convert the Unix timestamp 1631474654 to human readable time, we can use the following command:

date -d @1631474654

This will output the following:

Tue Sep 14 19:04:14 UTC 2021
Conclusion

Unix timestamp is a useful way of representing time in computer systems. In Bash shell, we can easily get the Unix timestamp and convert it to human readable time using the date command. With these tools, we can manipulate and work with time in our Bash scripts effectively.