The rdiff-backup command creates incremental backups by creating several files with datestamps in their titles. The datestamps are of the format defined in the W3 Note about datetime, which are essentially:

Complete date plus hours, minutes and seconds:

YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)

Where the T in the middle is a literal 'T' to denote that the time starts at this point.

I'd like to be able to mirror this format using the date command. So far I have:

date '+%FT%T%:z'

Which works brilliantly if I'm in any timezone other than GMT/UTC, giving the output in the expected format.

When in the GMT/UTC timezone, the timezone string at the end should be output as the letter Z rather than the current +00:00.

I'm sure I could do this by obtaining the timezone part with a separate date command and changing it if it matches +00:00, or by using some sort of parameter expansion if I save the string as a variable, or maybe even using tr. Is there a direct way within the date command options, if not how should I achieve this simply?

  • 2
    Does date --iso-8601=seconds do it for you? It looks about right for my locale/TZ on 16.04 Jan 24, 2017 at 13:45
  • @steeldriver I'd totally missed the timespec options, though it still outputs the timezone as +0000 when in GMT. Thanks for drawing my attention to it though.
    – Arronical
    Jan 24, 2017 at 14:26

1 Answer 1


I don't think GNU date has any option for printing Z instead of the UTC timezone. It's easy enough with sed:

$ date '+%FT%T%:z'       
$ date '+%FT%T%:z' | sed 's/+00:00$/Z/'                            
  • This'll be the best way to do it I think, it seems odd that there's no option to use Zulu time in GNU date.
    – Arronical
    Jan 24, 2017 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.