u123
u123

Reputation: 16331

Possible to specify UTC+3 to linux date when creating a timestamp string?

I am trying to create a timestamp string:

  TS=$(date -d "today" +"%Y_%d_%m_%H%M%S")
  echo "TS = $TS"

But I need it to be in UTC+3. The man pages on date does not show that as an option and I don't want to modify the OS locale.

I have tried:

$ date -d "today" +"%Y_%d_%m_%H%M%S +0300"
2020_16_04_090342 +0300

$ date -d "today" +"%Y_%d_%m_%H%M%S +0400"
2020_16_04_090347 +0400

So seems it has no effect. Also the string should NOT contain the offset, should just be:

2020_16_04_120347

Any suggestions?

Upvotes: 0

Views: 123

Answers (1)

VxJasonxV
VxJasonxV

Reputation: 975

man date

DATE STRING
The --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday". A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the info documentation.

date -d "today" +"%Y_%d_%m_%H%M%S +0300"

Upvotes: 1

Related Questions