Java Date Time Format Example

Jyotishgher Astrology
By -
0

Java SimpleDateFormat – Java Date Format


Java Date Time Format Example

We discussed about various aspects of DateFormat and SimpleDateFormat. Let us now look at some examples for different formats of date and time.
PatternResult
MM/dd/yyyy01/02/2018
dd-M-yyyy hh:mm:ss02-1-2018 06:07:59
dd MMMM yyyy02 January 2018
dd MMMM yyyy zzzz02 January 2018 India Standard Time
E, dd MMM yyyy HH:mm:ss zTue, 02 Jan 2018 18:07:59 IST


String pattern = "dd-MMM-yy";
String dateInString =new SimpleDateFormat(pattern).format(new Date());
Log.d(TAG, "onClick: " +dateInString);

onClick: 03-Mar-22


Letter for PatternDate or Time componentExamples
GEra designatorAD
yYear2018(yyyy),18(yy)
MMonth in yearJuly(MMMM), Jul(MMM), 07(MM)
wResults in week in year16
WResults in week in month3
DGives the day count in the year266
dDay of the month09(dd), 9(d)
FDay of the week in month4
EDay name in the weekTuesday, Tue
uDay number of week where 1 represents Monday, 2 represents Tuesday and so on2
aAM or PM markerAM
HHour in the day (0-23)12
kHour in the day (1-24)23
KHour in am/pm for 12 hour format (0-11)0
hHour in am/pm for 12 hour format (1-12)12
mMinute in the hour59
sSecond in the minute35
SMillisecond in the minute978
zTimezonePacific Standard Time; PST; GMT-08:00
ZTimezone offset in hours (RFC pattern)-0800

X
Timezone offset in ISO format-08; -0800; -08:00

Post a Comment

0Comments

Post a Comment (0)