Custom datetime formats
- Updated: 2024/10/30
Custom datetime formats
Custom datetime formats allow you to define specific patterns for converting datetime values into string representations. Use predefined conventions to specify a custom datetime format. These formats enable you to display dates and times in a way that suits your specific needs.
Format 'y' and 'Y'
For example, when you use a datetime format as 12/26/22 (2022/12/26), then perform actions to delete the files from the previous year, the datetime format ‘yy’ provides correct result (12/26/21) and the files from the year 2021 are deleted. If you use the datetime format ‘YY’ (indicating the year of the week in which the specific day appears), then files from the year 2022 will be deleted because the day 12/26/21 falls during the last week of 2021 and also during the first week of 2022.
We recommend that you use the datetime format 'yy' when you want to consider the calendar year only and not a specific week of that calendar year.
Format 'M'
Format 'd'
Specify a day as 'd' or 'dd'.
Format 'D'
Specify a day in a year as 'D' or 'DD'.
Format 'E'
Format 'F' or 'FF'
Format 'h' or 'H'
Format 'a'
Specify an AM/PM marker for the 12-hour time format.
Format 'm'
Specify a minute in an hour as 'mm'.
Format 's'
Specify a second in a minute as 'ss'.
Format 'S'
Specify a millisecond as 'SSS'.
Format 'z'
Specify a timezone, such as 'Pacific Standard Time' and 'Indian Standard Time'.
Format 'Z'
Specify an offset time for a timezone, such as '+0550' for 'Indian Standard Time'.
Examples
Format | Sample output |
yyyy-MM-dd | 2018-09-08 |
yyyy-M-d | 2018-9-8 |
dd-MM-yyyy | 08-09-2018 |
yyyy-MM-dd HH:mm:ss | 2018-09-08 23:50:55 |
hh:mm:ss.SSS a | 10:15:35.889 AM / 10:15:35.889 PM |
yyyy-MM-dd HH:mm:ss.SSS | 2018-09-08 23:50:55.999 |
yyyy-MM-dd HH:mm:ss.SSS Z | 2018-09-08 23:50:55.999 +0530 |
D:dd-MM-yyyy | 130:08-09-2018 |
D 'days', yyyy | 365 days, 2019 |