Date and Time Format Description

Overview

When handling and displaying date and time information, we usually need to organize and format this information according to a certain format. This document provides a set of commonly used date and time format symbols, along with their meanings, formats, and examples, to help you better understand and use these symbols.

Detailed Explanation of Format Symbols

SymbolDescriptionFormat ExampleExample Value
GEraAD; Anno DominiAD
yYearyear2020; 20
DDay of the yearnumber(3)189
MMonthmonth7; 07; Jul; July
dDay of the monthnumber(2)28
QQuarternumber/text3; 03; Q3; 3rd quarter
EDay of the weektextTue; Tuesday
aAM/PMam-pmPM
hHour (12-hour clock)number(2)12
KHour in AM/PM (0-11)number(2)0
kHour (24-hour clock)number(2)0
HHour (24-hour clock)number(2)0
mMinutenumber(2)30
sSecondnumber(2)55
SMillisecond/Microsecondfraction978
VTime zone IDzone-idAmerica/Los_Angeles; Z; -08:30
zTime zone namezone-namePacific Standard Time; PST
OLocalized time zone offsetoffset-OGMT+8; GMT+08:00; UTC-08:00;
XTime zone offsetoffset-XZ; -08; -0830; -08:30; -083015; -08:30:15;
ZTime zone offsetoffset-Z+0000; -0800; -08:00;
‘‘Single quoteliteral

Examples of Symbol Usage

  • Year:

    • yyyy: Four-digit year representation, e.g., 2022.
    • yy: Two-digit year representation, e.g., 22.
  • Month:

    • M: Single-digit month representation, e.g., 3, 12.
    • MM: Two-digit month representation, e.g., 03, 12.
  • Day of the month:

    • d: Single-digit day of the month representation, e.g., 5, 20.
    • dd: Two-digit day of the month representation, e.g., 05, 20.
  • Hour, 24-hour clock:

    • H: Single-digit hour in 24-hour clock representation, e.g., 1, 23.
    • HH: Two-digit hour in 24-hour clock representation, e.g., 01, 23.
  • Minute:

    • m: Single-digit minute representation, e.g., 4, 59.
    • mm: Two-digit minute representation, e.g., 04, 59.
  • Second:

    • s: Single-digit second representation, e.g., 8, 59.
    • ss: Two-digit second representation, e.g., 08, 59.
  • Millisecond/Microsecond:

    • S: Supports 1-9 digits, representing milliseconds (first 3 digits), microseconds (middle 3 digits), and nanoseconds (last 3 digits). Singdata currently only supports microsecond precision, so nanoseconds will be discarded when parsing time strings, and the nanosecond part will be set to zero when generating time strings. If less than 9 digits, precision decreases from right to left.

Examples

Here are some examples of date and time formats using the above symbols:

  • yyyy-MM-dd HH:mm:ss.SSSS: 2022-01-10 10:05:02.1232
  • yyyy/MM/dd HH:mm:ss.SSSS: 2022/01/10 10:05:0