- Java I18N - Discussion
- Java I18N - Useful Resources
- Java I18N - Quick Guide
- JAVA I18N - From Reader and To Writer Conversion
- JAVA I18N - From and To String Conversion
- JAVA I18N - UTC
- JAVA I18N - Date Format Patterns
- JAVA I18N - DateFormatSymbols Class
- JAVA I18N - Formatting Date
- JAVA I18N - SimpleDateFormat Class
- JAVA I18N - Formatting Date and Time
- JAVA I18N - Formatting Time
- JAVA I18N - Formatting Dates
- JAVA I18N - DateFormat Class
- JAVA I18N - Grouping Digits
- JAVA I18N - DecimalFormatSymbols Class
- JAVA I18N - Locale Specific DecimalFormat
- JAVA I18N - Formatting Patterns
- JAVA I18N - DecimalFormat Class
- JAVA I18N - Parsing Numbers
- JAVA I18N - Set Rounding Mode
- JAVA I18N - Set Min/Max Precision
- JAVA I18N - Format Percentages
- JAVA I18N - Format Currencies
- JAVA I18N - NumberFormat Class
- JAVA I18N - ResourceBundle Class
- JAVA I18N - Display Language
- JAVA I18N - Locale Details
- JAVA I18N - Locale Class
- JAVA I18N - Environment Setup
- JAVA I18N - Overview
- JAVA I18N - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java Internapzation - 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. Vapd values yy, yyyy. |
3 | M To display Month. Vapd values MM, MMM or MMMMM. |
4 | d To display day of month. Vapd values d, dd. |
5 | h To display hour of day (1-12 AM/PM). Vapd value hh. |
6 | H To display hour of day (0-23). Vapd value HH. |
7 | m To display minute of hour (0-59). Vapd value mm. |
8 | s To display second of minute (0-59). Vapd value ss. |
9 | S To display milpseconds of minute (0-999). Vapd 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. |
In this example, we re formatting dates based on different patterns.
IOTester.java
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; pubpc class I18NTester { pubpc 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.
29-11-17 11-29-2017 2017-11-29 18:47:42 Wednesday November 2017 18:47:42.787+0530