github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/job-specification/hcl2/functions/datetime/formatdate.mdx (about) 1 --- 2 layout: docs 3 page_title: formatdate - Functions - Configuration Language 4 description: The formatdate function converts a timestamp into a different time format. 5 --- 6 7 # `formatdate` Function 8 9 `formatdate` converts a timestamp into a different time format. 10 11 ```hcl 12 formatdate(spec, timestamp) 13 ``` 14 15 In Nomad, timestamps are conventionally represented as strings using [RFC 16 3339](https://tools.ietf.org/html/rfc3339) "Date and Time format" syntax. 17 `formatdate` requires the `timestamp` argument to be a string conforming to 18 this syntax. 19 20 ## Examples 21 22 ```shell-session 23 > formatdate("DD MMM YYYY hh:mm ZZZ", "2018-01-02T23:12:01Z") 24 02 Jan 2018 23:12 UTC 25 > formatdate("EEEE, DD-MMM-YY hh:mm:ss ZZZ", "2018-01-02T23:12:01Z") 26 Tuesday, 02-Jan-18 23:12:01 UTC 27 > formatdate("EEE, DD MMM YYYY hh:mm:ss ZZZ", "2018-01-02T23:12:01-08:00") 28 Tue, 02 Jan 2018 23:12:01 -0800 29 > formatdate("MMM DD, YYYY", "2018-01-02T23:12:01Z") 30 Jan 02, 2018 31 > formatdate("HH:mmaa", "2018-01-02T23:12:01Z") 32 11:12pm 33 ``` 34 35 ## Specification Syntax 36 37 The format specification is a string that includes formatting sequences from 38 the following table. This function is intended for producing common 39 _machine-oriented_ timestamp formats such as those defined in RFC822, RFC850, 40 and RFC1123. It is not suitable for truly human-oriented date formatting 41 because it is not locale-aware. In particular, it can produce month and day 42 names only in English. 43 44 The specification may contain the following sequences: 45 46 | Sequence | Result | 47 | -------- | ----------------------------------------------------------------------- | 48 | `YYYY` | Four (or more) digit year, like "2006". | 49 | `YY` | The year modulo 100, zero padded to at least two digits, like "06". | 50 | `MMMM` | English month name unabbreviated, like "January". | 51 | `MMM` | English month name abbreviated to three letters, like "Jan". | 52 | `MM` | Month number zero-padded to two digits, like "01" for January. | 53 | `M` | Month number with no padding, like "1" for January. | 54 | `DD` | Day of month number zero-padded to two digits, like "02". | 55 | `D` | Day of month number with no padding, like "2". | 56 | `EEEE` | English day of week name unabbreviated, like "Monday". | 57 | `EEE` | English day of week name abbreviated to three letters, like "Mon". | 58 | `hh` | 24-hour number zero-padded to two digits, like "02". | 59 | `h` | 24-hour number unpadded, like "2". | 60 | `HH` | 12-hour number zero-padded to two digits, like "02". | 61 | `H` | 12-hour number unpadded, like "2". | 62 | `AA` | Hour AM/PM marker in uppercase, like "AM". | 63 | `aa` | Hour AM/PM marker in lowercase, like "am". | 64 | `mm` | Minute within hour zero-padded to two digits, like "05". | 65 | `m` | Minute within hour unpadded, like "5". | 66 | `ss` | Second within minute zero-padded to two digits, like "09". | 67 | `s` | Second within minute, like "9". | 68 | `ZZZZZ` | Timezone offset with colon separating hours and minutes, like "-08:00". | 69 | `ZZZZ` | Timezone offset with just sign and digit, like "-0800". | 70 | `ZZZ` | Like `ZZZZ` but with a special case "UTC" for UTC. | 71 | `Z` | Like `ZZZZZ` but with a special case "Z" for UTC. | 72 73 Any non-letter characters, such as punctuation, are reproduced verbatim in the 74 output. To include literal letters in the format string, enclose them in single 75 quotes `'`. To include a literal quote, escape it by doubling the quotes. 76 77 ```shell-session 78 > formatdate("h'h'mm", "2018-01-02T23:12:01-08:00") 79 23h12 80 > formatdate("H 'o''clock'", "2018-01-02T23:12:01-08:00") 81 11 o'clock 82 ``` 83 84 This format specification syntax is intended to make it easy for a reader 85 to guess which format will result even if they are not experts on the syntax. 86 Therefore there are no predefined shorthands for common formats, but format 87 strings for various RFC-specified formats are given below to be copied into your 88 configuration as needed: 89 90 - [RFC 822](https://tools.ietf.org/html/rfc822#section-5) and 91 [RFC 2822](https://tools.ietf.org/html/rfc2822#section-3.3): 92 `"DD MMM YYYY hh:mm ZZZ"` 93 - [RFC 850](https://tools.ietf.org/html/rfc850#section-2.1.4): 94 `"EEEE, DD-MMM-YY hh:mm:ss ZZZ"` 95 - [RFC 1123](https://tools.ietf.org/html/rfc1123#section-5.2.14): 96 `"EEE, DD MMM YYYY hh:mm:ss ZZZ"` 97 - [RFC 3339](https://tools.ietf.org/html/rfc3339): 98 `"YYYY-MM-DD'T'hh:mm:ssZ"` (but this is also the input format, so such a 99 conversion is redundant.) 100 101 ## Related Functions 102 103 - [`format`](/docs/job-specification/hcl2/functions/string/format) is a more general formatting function for arbitrary 104 data.