Supported Date and Time Formats in C#
This document provides an overview of the supported formats for date and time in the LPS tool. Behind the scenes, our code is a C# code, and utilizes DateTime.UtcNow.ToString(format) to generate timestamps in the specified format.
C# provides extensive support for handling dates and times format. Below are the commonly used formats for dates and times in C#.
Standard Date and Time Format Strings
| Format | Description | Example Output |
|---|---|---|
d |
Short date | 12/25/2024 |
D |
Long date | Wednesday, December 25, 2024 |
f |
Full date/time (short time) | Wednesday, December 25, 2024 1:30 PM |
F |
Full date/time (long time) | Wednesday, December 25, 2024 1:30:45 PM |
g |
General date/time (short time) | 12/25/2024 1:30 PM |
G |
General date/time (long time) | 12/25/2024 1:30:45 PM |
m or M |
Month day | December 25 |
o or O |
Round-trip date/time | 2024-12-25T13:30:45.0000000 |
r or R |
RFC1123 date | Wed, 25 Dec 2024 13:30:45 GMT |
s |
Sortable date/time | 2024-12-25T13:30:45 |
t |
Short time | 1:30 PM |
T |
Long time | 1:30:45 PM |
u |
Universal sortable date/time | 2024-12-25 13:30:45Z |
y or Y |
Year month | December 2024 |
Custom Date and Time Format Strings
| Format | Description | Example Output |
|---|---|---|
yyyy |
Four-digit year | 2024 |
yy |
Two-digit year | 24 |
MMMM |
Full month name | December |
MMM |
Abbreviated month name | Dec |
MM |
Two-digit month | 12 |
M |
Single-digit month | 1 (for January) |
dddd |
Full day of the week | Wednesday |
ddd |
Abbreviated day of the week | Wed |
dd |
Two-digit day | 25 |
d |
Single-digit day | 5 (for the 5th) |
HH |
Two-digit hour (24-hour clock) | 13 |
H |
Single-digit hour (24-hour clock) | 3 |
hh |
Two-digit hour (12-hour clock) | 01 |
h |
Single-digit hour (12-hour clock) | 1 |
mm |
Two-digit minutes | 30 |
ss |
Two-digit seconds | 45 |
fff |
Three-digit milliseconds | 123 |
ff |
Two-digit fractions of a second | 12 |
f |
Single-digit fraction of a second | 1 |
tt |
AM/PM designator | PM |
K |
Time zone information | +02:00 |
Examples
payload:
type: Raw
raw: '{"key": "$timestamp(format=F)"}'
payload:
type: Raw
raw: '{"key": "$timestamp(format=yyyy-MM-dd HH:mm)"}'
For more details, refer to the official Microsoft documentation: Standard date and time format strings.