- Java I18N - Home
- Java I18N - Overview
- Java I18N - Environment Setup
- Locale Class Examples
- Java I18N - Locale Class
- Java I18N - Locale Details
- Java I18N - Display Language
- ResourceBundle Class Examples
- Java I18N - ResourceBundle Class
- NumberFormat Class Examples
- Java I18N - NumberFormat Class
- Java I18N - Format Currencies
- Java I18N - Format Percentages
- Java I18N - Set Min/Max Precision
- Java I18N - Set Rounding Mode
- Java I18N - Parsing Numbers
- DecimalFormat Class Examples
- Java I18N - DecimalFormat Class
- Java I18N - Formatting Patterns
- Java I18N - Locale Specific DecimalFormat
- Java I18N - DecimalFormatSymbols Class
- Java I18N - Grouping Digits
- DateFormat Class Examples
- Java Java - DateFormat Class
- Java I18N - Formatting Dates
- Java I18N - Formatting Time
- Java I18N - Formatting Date and Time
- SimpleDateFormat Class Examples
- Java I18N - SimpleDateFormat Class
- Java I18N - Formatting Date
- Java I18N - DateFormatSymbols Class
- Java I18N - Date Format Patterns
- Time Zones Examples
- Java I18N - UTC
- Unicode Conversion
- Java I18N - From and To String Conversion
- Java I18N - From Reader and To Writer Conversion
- Related Tutorials
- Java Tutorial
- JDBC Tutorial
- SWING Tutorial
- AWT Tutorial
- Servlets Tutorial
- JSP Tutorial
- Java I18N Useful Resources
- Java I18N - Quick Guide
- Java I18N - Useful Resources
- Java I18N - Discussion
Java Internationalization - Date Format Patterns
Followings is the use of characters in date formatting patterns.
| Sr.No. | Class & Description |
|---|---|
| 1 | G To display Era. |
| 2 | y To display Year. Valid values yy, yyyy. |
| 3 | M To display Month. Valid values MM, MMM or MMMMM. |
| 4 | d To display day of month. Valid values d, dd. |
| 5 | h To display hour of day (1-12 AM/PM). Valid value hh. |
| 6 | H To display hour of day (0-23). Valid value HH. |
| 7 | m To display minute of hour (0-59). Valid value mm. |
| 8 | s To display second of minute (0-59). Valid value ss. |
| 9 | S To display milliseconds of minute (0-999). Valid value SSS. |
| 10 | E To display Day in week (e.g Monday, Tuesday etc.) |
| 11 | D To display Day in year (1-366). |
| 12 | F To display Day of week in month (e.g. 1st Thursday of December). |
| 13 | w To display Week in year (1-53). |
| 14 | W To display Week in month (0-5) |
| 15 | a To display AM / PM |
| 16 | k To display Hour in day (1-24). |
| 17 | K To display Hour in day, AM / PM (0-11). |
| 18 | z To display Time Zone. |
Example
In this example, we're formatting dates based on different patterns.
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class I18NTester { public static void main(String[] args) throws ParseException { String pattern = "dd-MM-yy"; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); Date date = new Date(); System.out.println(simpleDateFormat.format(date)); pattern = "MM-dd-yyyy"; simpleDateFormat = new SimpleDateFormat(pattern); System.out.println(simpleDateFormat.format(date)); pattern = "yyyy-MM-dd HH:mm:ss"; simpleDateFormat = new SimpleDateFormat(pattern); System.out.println(simpleDateFormat.format(date)); pattern = "EEEEE MMMMM yyyy HH:mm:ss.SSSZ"; simpleDateFormat = new SimpleDateFormat(pattern); System.out.println(simpleDateFormat.format(date)); } } Output
It will print the following result.
07-06-24 06-07-2024 2024-06-07 16:04:40 Friday June 2024 16:04:40.866+0530