Here are some common placeholders you can use in your custom patterns:
- Year:
y
: Year (2 digits)yy
: Year (4 digits)yyyy
: Year (4 digits, zero-padded)
- Month:
M
: Month (1 or 2 digits)MM
: Month (2 digits, zero-padded)MMM
: Abbreviated month name (e.g., “Jan”)MMMM
: Full month name (e.g., “January”)
- Day:
d
: Day of the month (1 or 2 digits)dd
: Day of the month (2 digits, zero-padded)
- Hour:
h
: Hour (1 or 2 digits, 12-hour clock)hh
: Hour (2 digits, zero-padded, 12-hour clock)H
: Hour (1 or 2 digits, 24-hour clock)HH
: Hour (2 digits, zero-padded, 24-hour clock)
- Minute:
m
: Minute (1 or 2 digits)mm
: Minute (2 digits, zero-padded)
- Second:
s
: Second (1 or 2 digits)ss
: Second (2 digits, zero-padded)
- Timezone:
z
: Timezone abbreviation (e.g., “PST”)zzzz
: Full timezone name (e.g., “Pacific Standard Time”)
- Other:
a
: AM/PM markerE
: Day of the week (abbreviated)EEEE
: Full day of the week
For example, if you want to format a date as “YYYY-MM-dd HH:mm:ss z” (e.g., “2024-04-01 14:30:45 PDT”), you can set the pattern like this:
This is the link to the information on Formatting Dates and Times.