CSharp - Date Time Format Strings

Introduction

Format strings for DateTime/DateTimeOffset can be divided into two groups, based on whether they honor culture and format provider settings.

The following table lists Culture-sensitive date/time format strings.

Sample output uses the value of new DateTime (2000, 1, 2, 17, 18, 19);

Format string
Meaning
Sample output
d
Short date
01/02/2000
D
Long date
Sunday, 02 January 2000
t
Short time
17:18
T
Long time
17:18:19
f
Long date + short time
Sunday, 02 January 2000 17:18
F
Long date + long time
Sunday, 02 January 2000 17:18:19
g
Short date + short time
01/02/2000 17:18
G (default)
Short date + long time
01/02/2000 17:18:19
m, M
Month and day
02 January
y, Y
Year and month
January 2000

The following table lists Culture-insensitive date/time format strings.

Format
string
Meaning

Sample output

Notes

o


Round-
trippable

2000-01-02T17:18:19.0000000


Will append time zone
information unless DateTime
Kind is Unspecified
r, R


RFC 1123
standard

Sun, 02 Jan 2000 17:18:19 GMT


You must explicitly convert to
UTC with DateTime.ToUni
versalTime
s

Sortable; ISO
8601
2000-01-02T17:18:19

Compatible with text-based
sorting
u

"Universal"
sortable
2000-01-02 17:18:19Z

Similar to above; must explicitly
convert to UTC
U

UTC

Sunday, 02 January 2000
17:18:19
Long date + short time,
converted to UTC