Преобразование в строку

Простые типы / Дата и время

#the time zone of the example; without it the local one is used
export TZ=UTC

#a fixed moment keeps the output the same; for the current date take -1
moment=1700000000

#bash's printf formats a date itself: %(format)T
printf -v shortStyle '%(%m/%d/%y %I:%M %p)T' "$moment"
#shortStyle is "11/14/23 10:13 PM"

printf -v customStyle '%(%Y-%m-%d)T' "$moment"
#customStyle is "2023-11-14"

#date does the same with +format, -d @seconds sets the moment
standardStyle=$(date -d "@$moment" '+%F %T')
#standardStyle is "2023-11-14 22:13:20"

strFormat=$(date -d "@$moment" '+Today %d %B, %A')
#strFormat is "Today 14 November, Tuesday"

#ISO 8601 with the time zone
isoStyle=$(date -d "@$moment" -Iseconds)
#isoStyle is "2023-11-14T22:13:20+00:00"

echo "shortStyle is $shortStyle"
echo "customStyle is $customStyle"
echo "standardStyle is $standardStyle"
echo "strFormat is $strFormat"
echo "isoStyle is $isoStyle"