Conversion characters for date in Java

Java 8Object Oriented ProgrammingProgramming

The following are the conversion characters for date-time −

cComplete date and time
FISO 8601 date
DU.S. formatted date (month/day/year)
T24-hour time
r12-hour time
R24-hour time, no seconds
YFour-digit year (with leading zeroes)
yLast two digits of the year (with leading zeroes)
CFirst two digits of the year (with leading zeroes)
BFull month name
bAbbreviated month name
mTwo-digit month (with leading zeroes)
dTwo-digit day (with leading zeroes)
eTwo-digit day (without leading zeroes)
AFull weekday name
aAbbreviated weekday name
jThree-digit day of year (with leading zeroes)
HTwo-digit hour (with leading zeroes), between 00 and 23
kTwo-digit hour (without leading zeroes), between 0 and 23
ITwo-digit hour (with leading zeroes), between 01 and 12
lTwo-digit hour (without leading zeroes), between 1 and 12
MTwo-digit minutes (with leading zeroes)
STwo-digit seconds (with leading zeroes)
LThree-digit milliseconds (with leading zeroes)
NNine-digit nanoseconds (with leading zeroes)
PUppercase morning or afternoon marker
pLowercase morning or afternoon marker
zRFC 822 numeric offset from GMT
ZTime zone
sSeconds since 1970-01-01 00:00:00 GMT
QMilliseconds since 1970-01-01 00:00:00 GMT

The following is an example −


 Live Demo

import java.util.Calendar;
public class Demo {
   public static void main( String args[] ) {
      Calendar cal = Calendar.getInstance();
      System.out.printf( "%1$tA, %1$tB %1$td, %1$tY\n", cal );
      System.out.printf( "%1$ta, %1$tb %1$te, %1$ty\n", cal );


Monday, November 26, 2018
Mon, Nov 26, 18
Updated on 27-Jun-2020 05:14:05