Java Date Format Pattern

Java SimpleDateFormat Date and time formats are specified by date and time pattern strings. Within format strings, unquoted letters from ‘A’ to ‘Z’ and from ‘a’ to ‘z’ are treated as format letters representing the components of a date or time string.

The following pattern letters are defined:
G – Era designator – AD
y – Year – 2014; 14
Y – Week year – 2014; 14
M – Month in year (context sensitive) – July; Jul; 07
L – Month in year (standalone form) – July; Jul; 07
w – Week in year – 27
W – Week in month – 2
D – Day in year – 189
d – Day in month – 10
F – Day of week in month – 2
E – Day name in week – Tuesday; Tue
u – Day number of week (1 = Monday, …, 7 = Sunday) – 1
a – Am/pm marker – PM
H – Hour in day (0-23) – 0
k – Hour in day (1-24) – 24
K – Hour in am/pm (0-11) – 0
h – Hour in am/pm (1-12) – 12
m – Minute in hour – 30
s – Second in minute – 55
S – Millisecond – 978
z – Time zone – Pacific Standard Time; PST; GMT-08:00
Z – Time zone – -0800
X – Time zone – -08; -0800; -08:00

Example

Date and Time Pattern Result

“yyyy.MM.dd G ‘at’ HH:mm:ss z” 2017.08.04 AD at 12:08:56 PDT
 “yyyy-MM-dd’T’HH:mm:ss.SSSZ  2017-07-04T12:08:56.235-0700
 “yyyy-MM-dd’T’HH:mm:ss.SSSXXX”  2017-07-04T12:08:56.235-07:00
 “EEE, d MMM yyyy HH:mm:ss Z”  Wed, 4 Jul 2001 12:08:56 -0700
 “K:mm a, z”  0:08 PM, PDT
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponEmail this to someoneShare on TumblrDigg this

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">