Print Timestamp in Shell: Quick Guide

You can use the date command to print timestamp information in the shell. Here are some commonly used methods:

  1. Print the current timestamp.
date +%s
  1. Print the current timestamp and format the output.
date '+%Y-%m-%d %H:%M:%S'
  1. Print the date information for a specified timestamp.
date -d @<timestamp> '+%Y-%m-%d %H:%M:%S'

In this context, %s represents the number of seconds from January 1, 1970, 00:00:00 UTC to the current time, %Y represents the 4-digit year, %m represents the month, %d represents the date, %H represents the hour, %M represents the minute, and %S represents the second.

bannerAds