It’s date formatting string time! This is the table you need for all simple date formatting in Java/Kotlin.
To be used with:
SimpleDateFormat("pattern", Locale.getDefault())
The patterns
Pattern | Description | Example |
---|---|---|
G | Era | AD |
y | Year | 2018 (yyyy), 18 (yy) |
M | Month of the year | July (MMMM), Jul (MMM), 07 (MM) |
w | Week of the year | 16 |
W | Week of the month | 3 |
D | Day of the year | 266 |
d | Day of the month | 09 (dd), 9 (d) |
F | Day of the week in month | 4 |
E | Day name in the week | Tuesday (EEEE), Tue (EEE) |
u | Day number of week, where 1 represents Monday, 2 represents Tuesday and so on | 2 |
a | AM or PM | AM |
H | Hour in the day, 24h format (0-23) | 12 |
k | Hour in the day, 24h format (1-24) | 23 |
K | Hour in the day, 12h format (0-11) | 0 |
h | Hour in the day, 12h format (1-12) | 12 |
m | Minute in the hour | 59 |
s | Second in the minute | 35 |
S | Millisecond in the minute | 978 |
z | Timezone | Pacific Standard Time; PST; GMT-08:00 |
Z | Timezone offset in hours (RFC pattern) | -0800 |
X | Timezone offset in ISO format | -08; -0800; -08:00 |