Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 time 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();
// date
System.out.printf("Date....\n");
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 );
// time
System.out.printf("\nTime....\n");
System.out.printf( "%1$tH:%1$tM:%1$tS\n", cal );
System.out.printf( "%1$tZ %1$tI:%1$tM:%1$tS", cal );
}
}
Output
Date.... Monday, November 26, 2018 Mon, Nov 26, 18 Time.... 12:41:28 UTC 12:41:28
Advertisements