Date & Time

Date Format Strings

Complete reference for date and time format strings across C#/.NET, JavaScript, and Python. Includes standard formats, custom patterns, and common examples.

Quick Reference

Quick reference for date/time formatting across popular programming languages.

C# / .NET Format Strings

Standard Date/Time Formats

Format Pattern Example
d Short date 1/24/2026
D Long date Saturday, January 24, 2026
t Short time 2:30 PM
T Long time 2:30:45 PM
f Full (short time) Saturday, January 24, 2026 2:30 PM
F Full (long time) Saturday, January 24, 2026 2:30:45 PM
g General (short time) 1/24/2026 2:30 PM
G General (long time) 1/24/2026 2:30:45 PM
M or m Month/day January 24
Y or y Year/month January 2026
s Sortable 2026-01-24T14:30:45
u Universal sortable 2026-01-24 14:30:45Z
o or O Round-trip 2026-01-24T14:30:45.0000000
r or R RFC 1123 Sat, 24 Jan 2026 14:30:45 GMT

Custom Format Specifiers

Specifier Description Example
d Day (1-31) 5
dd Day (01-31) 05
ddd Abbreviated day Sat
dddd Full day name Saturday
M Month (1-12) 1
MM Month (01-12) 01
MMM Abbreviated month Jan
MMMM Full month name January
y Year (0-99) 26
yy Year (00-99) 26
yyyy 4-digit year 2026
h Hour 12h (1-12) 2
hh Hour 12h (01-12) 02
H Hour 24h (0-23) 14
HH Hour 24h (00-23) 14
m Minute (0-59) 5
mm Minute (00-59) 05
s Second (0-59) 9
ss Second (00-59) 09
f - fffffff Fractional seconds 1234567
t AM/PM (first char) P
tt AM/PM PM
K Time zone +00:00
z UTC offset hours +10
zz UTC offset (2 digits) +10
zzz UTC offset (full) +10:00

C# Examples

DateTime now = DateTime.Now;

now.ToString("yyyy-MM-dd")           // "2026-01-24"
now.ToString("dd/MM/yyyy")           // "24/01/2026"
now.ToString("MMMM d, yyyy")         // "January 24, 2026"
now.ToString("HH:mm:ss")             // "14:30:45"
now.ToString("h:mm tt")              // "2:30 PM"
now.ToString("yyyy-MM-ddTHH:mm:ss")  // "2026-01-24T14:30:45"
now.ToString("ddd, dd MMM yyyy")     // "Sat, 24 Jan 2026"

JavaScript Date Formatting

Intl.DateTimeFormat Options

Option Values Example
dateStyle "full", "long", "medium", "short" Saturday, January 24, 2026
timeStyle "full", "long", "medium", "short" 2:30:45 PM EST
year "numeric", "2-digit" 2026, 26
month "numeric", "2-digit", "long", "short", "narrow" 1, 01, January, Jan, J
day "numeric", "2-digit" 24, 24
weekday "long", "short", "narrow" Saturday, Sat, S
hour "numeric", "2-digit" 2, 02
minute "numeric", "2-digit" 30, 30
second "numeric", "2-digit" 45, 45
hour12 true, false 12h or 24h format
timeZoneName "long", "short" Eastern Standard Time, EST

toLocaleString() Options

const date = new Date('2026-01-24T14:30:45');

// Short date
date.toLocaleDateString('en-US')
// "1/24/2026"

// Long date
date.toLocaleDateString('en-US', { 
  weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' 
})
// "Saturday, January 24, 2026"

// ISO format
date.toISOString()
// "2026-01-24T14:30:45.000Z"

// Custom formatting
date.toLocaleDateString('en-US', { year: 'numeric', month: '2-digit', day: '2-digit' })
// "01/24/2026"

// Time only
date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' })
// "02:30 PM"

Date Methods

Method Returns Example
getFullYear() 4-digit year 2026
getMonth() Month (0-11) 0 (January)
getDate() Day of month 24
getDay() Day of week (0-6) 6 (Saturday)
getHours() Hours (0-23) 14
getMinutes() Minutes (0-59) 30
getSeconds() Seconds (0-59) 45
getMilliseconds() Milliseconds 0
getTime() Unix timestamp (ms) 1769350245000
toISOString() ISO 8601 string 2026-01-24T14:30:45.000Z

Python strftime/strptime

Format Codes

Code Description Example
%a Abbreviated weekday Sat
%A Full weekday Saturday
%w Weekday number (0-6) 6
%d Day (01-31) 24
%b Abbreviated month Jan
%B Full month January
%m Month (01-12) 01
%y Year (00-99) 26
%Y 4-digit year 2026
%H Hour 24h (00-23) 14
%I Hour 12h (01-12) 02
%p AM/PM PM
%M Minute (00-59) 30
%S Second (00-59) 45
%f Microsecond 000000
%z UTC offset +0000
%Z Timezone name UTC
%j Day of year (001-366) 024
%U Week number (Sunday start) 03
%W Week number (Monday start) 03
%c Locale date/time Sat Jan 24 14:30:45 2026
%x Locale date 01/24/26
%X Locale time 14:30:45
%% Literal % %

Python Examples

from datetime import datetime

dt = datetime(2026, 1, 24, 14, 30, 45)

dt.strftime('%Y-%m-%d')              # '2026-01-24'
dt.strftime('%d/%m/%Y')              # '24/01/2026'
dt.strftime('%B %d, %Y')             # 'January 24, 2026'
dt.strftime('%H:%M:%S')              # '14:30:45'
dt.strftime('%I:%M %p')              # '02:30 PM'
dt.strftime('%Y-%m-%dT%H:%M:%S')     # '2026-01-24T14:30:45'
dt.strftime('%a, %d %b %Y')          # 'Sat, 24 Jan 2026'

# Parsing
datetime.strptime('2026-01-24', '%Y-%m-%d')
datetime.strptime('24/01/2026 14:30', '%d/%m/%Y %H:%M')

Common Format Patterns

Format C# JavaScript Python
ISO 8601 yyyy-MM-ddTHH:mm:ss toISOString() %Y-%m-%dT%H:%M:%S
US Date M/d/yyyy toLocaleDateString('en-US') %m/%d/%Y
EU Date d/M/yyyy toLocaleDateString('en-GB') %d/%m/%Y
Long Date MMMM d, yyyy { month: 'long', day: 'numeric', year: 'numeric' } %B %d, %Y
RFC 2822 r toUTCString() %a, %d %b %Y %H:%M:%S %z
Unix Timestamp DateTimeOffset.ToUnixTimeSeconds() getTime() / 1000 timestamp()
24h Time HH:mm { hour: '2-digit', minute: '2-digit', hour12: false } %H:%M
12h Time h:mm tt { hour: 'numeric', minute: '2-digit' } %I:%M %p
Related Topics
date format datetime format strftime date formatting C# date JavaScript date Python date
Share this reference