[date] Get the current date and time in a specified format

Created on November 30, 2026

Use date with + followed by the format string. The example sets TZ for the command so it formats the current time in the Asia/Tokyo time zone.

date_string=`TZ=Asia/Tokyo date "+%Y-%m-%d %H:%M:%S"`
echo $date_string

Example output

2020-03-10 09:00:00
Shell command Bash