- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Conversion characters for date in Java
The following are the conversion characters for date-time −
Character | Description |
---|---|
c | Complete date and time |
F | ISO 8601 date |
D | U.S. formatted date (month/day/year) |
T | 24-hour time |
r | 12-hour time |
R | 24-hour time, no seconds |
Y | Four-digit year (with leading zeroes) |
y | Last two digits of the year (with leading zeroes) |
C | First two digits of the year (with leading zeroes) |
B | Full month name |
b | Abbreviated month name |
m | Two-digit month (with leading zeroes) |
d | Two-digit day (with leading zeroes) |
e | Two-digit day (without leading zeroes) |
A | Full weekday name |
a | Abbreviated weekday name |
j | Three-digit day of year (with leading zeroes) |
H | Two-digit hour (with leading zeroes), between 00 and 23 |
k | Two-digit hour (without leading zeroes), between 0 and 23 |
I | Two-digit hour (with leading zeroes), between 01 and 12 |
l | Two-digit hour (without leading zeroes), between 1 and 12 |
M | Two-digit minutes (with leading zeroes) |
S | Two-digit seconds (with leading zeroes) |
L | Three-digit milliseconds (with leading zeroes) |
N | Nine-digit nanoseconds (with leading zeroes) |
P | Uppercase morning or afternoon marker |
p | Lowercase morning or afternoon marker |
z | RFC 822 numeric offset from GMT |
Z | Time zone |
s | Seconds since 1970-01-01 00:00:00 GMT |
Q | Milliseconds since 1970-01-01 00:00:00 GMT |
The following is an example −
Example
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
", cal ); System.out.printf( "%1$ta, %1$tb %1$te, %1$ty
", cal ); } }
Output
Monday, November 26, 2018 MONDAY, NOVEMBER 26, 2018 Mon, Nov 26, 18
- Related Articles
- Conversion characters for time in Java
- Integral conversion characters in Java
- Floating-point conversion characters in Java
- Display nanoseconds with Java Date and Time Conversion Character
- Displaymilliseconds since the epoch with Java Date and Time Conversion Character
- Java program for Hexadecimal to Decimal Conversion
- Java Program for Decimal to Binary Conversion
- Java Program for Int to Char Conversion
- Different ways for Integer to String conversion in Java
- Display seconds since the epoch with Java Date and Time Conversion Character
- Narrowing Conversion in Java
- What are printf conversion characters and their types?
- Widening Primitive Conversion in Java
- Data Conversion Using valueOf() In Java.
- What is type conversion in java?

Advertisements