Date and time formats are well described below

SimpleDateFormat (Java Platform SE 7) - Date and Time Patterns

There could be n Number of formats you can possibly make. ex - dd/MM/yyyy or YYYY-'W'ww-u or you can mix and match the letters to achieve your required pattern. Pattern letters are as follow.

  • G - Era designator (AD)
  • y - Year (1996; 96)
  • Y - Week Year (2009; 09)
  • M - Month in year (July; Jul; 07)
  • w - Week in year (27)
  • W - Week in month (2)
  • D - Day in year (189)
  • d - Day in month (10)
  • F - Day of week in month (2)
  • E - Day name in week (Tuesday; Tue)
  • u - Day number of week (1 = Monday, ..., 7 = Sunday)
  • a - AM/PM marker
  • H - Hour in day (0-23)
  • k - Hour in day (1-24)
  • K - Hour in am/pm (0-11)
  • h - Hour in am/pm (1-12)
  • m - Minute in hour (30)
  • s - Second in minute (55)
  • S - Millisecond (978)
  • z - General time zone (Pacific Standard Time; PST; GMT-08:00)
  • Z - RFC 822 time zone (-0800)
  • X - ISO 8601 time zone (-08; -0800; -08:00)

To parse:

2000-01-23T04:56:07.000+0000

Use: new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

Answer from Subhrajyoti Majumder on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-simpledateformat-java-date-format
Master Java Date Formatting: SimpleDateFormat & DateFormat Guide | DigitalOcean
December 20, 2024 - Master Java date and time formatting with SimpleDateFormat and DateFormat. Learn locale-based patterns and parsing techniques to enhance your java applications!
Top answer
1 of 4
191

Date and time formats are well described below

SimpleDateFormat (Java Platform SE 7) - Date and Time Patterns

There could be n Number of formats you can possibly make. ex - dd/MM/yyyy or YYYY-'W'ww-u or you can mix and match the letters to achieve your required pattern. Pattern letters are as follow.

  • G - Era designator (AD)
  • y - Year (1996; 96)
  • Y - Week Year (2009; 09)
  • M - Month in year (July; Jul; 07)
  • w - Week in year (27)
  • W - Week in month (2)
  • D - Day in year (189)
  • d - Day in month (10)
  • F - Day of week in month (2)
  • E - Day name in week (Tuesday; Tue)
  • u - Day number of week (1 = Monday, ..., 7 = Sunday)
  • a - AM/PM marker
  • H - Hour in day (0-23)
  • k - Hour in day (1-24)
  • K - Hour in am/pm (0-11)
  • h - Hour in am/pm (1-12)
  • m - Minute in hour (30)
  • s - Second in minute (55)
  • S - Millisecond (978)
  • z - General time zone (Pacific Standard Time; PST; GMT-08:00)
  • Z - RFC 822 time zone (-0800)
  • X - ISO 8601 time zone (-08; -0800; -08:00)

To parse:

2000-01-23T04:56:07.000+0000

Use: new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

2 of 4
55

Let me throw out some example code that I got from http://www3.ntu.edu.sg/home/ehchua/programming/java/DateTimeCalendar.html Then you can play around with different options until you understand it.

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTest {
   public static void main(String[] args) {
       Date now = new Date();

       //This is just Date's toString method and doesn't involve SimpleDateFormat
       System.out.println("toString(): " + now);  // dow mon dd hh:mm:ss zzz yyyy
       //Shows  "Mon Oct 08 08:17:06 EDT 2012"

       SimpleDateFormat dateFormatter = new SimpleDateFormat("E, y-M-d 'at' h:m:s a z");
       System.out.println("Format 1:   " + dateFormatter.format(now));
       // Shows  "Mon, 2012-10-8 at 8:17:6 AM EDT"

       dateFormatter = new SimpleDateFormat("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
       System.out.println("Format 2:   " + dateFormatter.format(now));
       // Shows  "Mon 2012.10.08 at 08:17:06 AM EDT"

       dateFormatter = new SimpleDateFormat("EEEE, MMMM d, yyyy");
       System.out.println("Format 3:   " + dateFormatter.format(now));
       // Shows  "Monday, October 8, 2012"

       // SimpleDateFormat can be used to control the date/time display format:
       //   E (day of week): 3E or fewer (in text xxx), >3E (in full text)
       //   M (month): M (in number), MM (in number with leading zero)
       //              3M: (in text xxx), >3M: (in full text full)
       //   h (hour): h, hh (with leading zero)
       //   m (minute)
       //   s (second)
       //   a (AM/PM)
       //   H (hour in 0 to 23)
       //   z (time zone)
       //  (there may be more listed under the API - I didn't check)

   }

}

Good luck!

People also ask

How can I change the date format in Java?
In Java, you can change the date format by utilizing the DateFormat or SimpleDateFormat class. Create an instance of the desired date format, and then use the format() method to convert a date to a string with the new format.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › dateformat in java
Mastering DateFormat in Java: A Comprehensive Guide
How do I convert a string to a date in Java?
To convert a string to a date in Java, you can use the parse() method of the DateFormat or SimpleDateFormat class. Create an instance of the desired date format, and then call the parse() method, passing the string as an argument.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › dateformat in java
Mastering DateFormat in Java: A Comprehensive Guide
How can I handle time zones when working with dates in Java?
When working with time zones in Java, consider using the classes from the java.time package, such as ZonedDateTime. These classes provide built-in support for handling time zones and converting dates between different time zones.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › dateformat in java
Mastering DateFormat in Java: A Comprehensive Guide
🌐
Gooddata
help.gooddata.com › cloudconnect › manual › date-and-time-format.html
Data and Time Format
The number of symbol letters you specify also determines the format. For example, if the "zz" pattern results in "PDT", then the "zzzz" pattern generates "Pacific Daylight Time". The following table summarizes these rules: Table 28.4. Rules for Date Format Usage (Java)
🌐
Baeldung
baeldung.com › home › java › java dates › guide to datetimeformatter
Guide to DateTimeFormatter | Baeldung
March 26, 2025 - There are also pattern letters that can be used for time patterns: Symbol Meaning Presentation Examples ------ ------- ------------ ------- H hour-of-day (0-23) number 0 m minute-of-hour number 30 s second-of-minute number 55 S fraction-of-second fraction 978 n nano-of-second number 987654321 · It’s quite simple to use DateTimeFormatter to format a java.time.LocalTime instance.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › text › SimpleDateFormat.html
SimpleDateFormat (Java Platform SE 7 )
Date and time formats are specified by date and time pattern strings. Within date and time pattern strings, unquoted letters from 'A' to 'Z' and from 'a' to 'z' are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes (') ...
🌐
Jenkov
jenkov.com › tutorials › java-internationalization › simpledateformat.html
Java SimpleDateFormat
The Java SimpleDateFormat class can parse and format dates according to custom date patterns. This Java SimpleDateFormat tutorial explains how to use the SimpleDateFormat class.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › text › SimpleDateFormat.html
SimpleDateFormat (Java Platform SE 8 )
October 20, 2025 - Date and time formats are specified by date and time pattern strings. Within date and time pattern strings, unquoted letters from 'A' to 'Z' and from 'a' to 'z' are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes (') ...
Find elsewhere
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › text › SimpleDateFormat.html
SimpleDateFormat (Java SE 11 & JDK 11 )
January 20, 2026 - Letter M is context-sensitive in the sense that when it is used in the standalone pattern, for example, "MMMM", it gives the standalone form of a month name and when it is used in the pattern containing other field(s), for example, "d MMMM", it gives the format form of a month name. For example, January in the Catalan language is "de gener" in the format form while it is "gener" in the standalone form. In this case, "MMMM" will produce "gener" and the month part of the "d MMMM" will produce "de gener". If a DateFormatSymbols has been set explicitly with constructor SimpleDateFormat(String,DateFormatSymbols) or method setDateFormatSymbols(DateFormatSymbols), the month names given by the DateFormatSymbols are used.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › dateformat in java
Mastering DateFormat in Java: A Comprehensive Guide
September 9, 2025 - Java's DateFormat class is an indispensable tool for formatting and parsing dates. It offers a collection of methods for converting dates to strings (formatting) and strings to dates (parsing) based on specific patterns and formats.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › time › format › DateTimeFormatter.html
DateTimeFormatter (Java Platform SE 8 )
October 20, 2025 - This method will create a formatter based on a simple pattern of letters and symbols as described in the class documentation. For example, d MMM uuuu will format 2011-12-03 as '3 Dec 2011'. The formatter will use the specified locale. This can be changed using withLocale(Locale) on the returned formatter · The returned formatter has no override chronology or zone. It uses SMART resolver style. ... Returns a locale specific date format for the ISO chronology.
🌐
TutorialsPoint
tutorialspoint.com › java_i18n › java_i18n_dateformat_patterns.htm
Java Internationalization - Date Format Patterns
In this example, we're formatting ... 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 ...
🌐
Jenkov
jenkov.com › tutorials › java-date-time › parsing-formatting-dates.html
Parsing and Formatting Dates in Java
Here are a few pattern examples, with examples of how each pattern would format or expect to parse a date: yyyy-MM-dd (2009-12-31) dd-MM-YYYY (31-12-2009) yyyy-MM-dd HH:mm:ss (2009-12-31 23:59:59) HH:mm:ss.SSS (23:59.59.999) yyyy-MM-dd HH:mm:ss.SSS ...
🌐
Oracle
docs.oracle.com › javase › 10 › docs › api › java › text › SimpleDateFormat.html
SimpleDateFormat (Java SE 10 & JDK 10 )
Letter M is context-sensitive in the sense that when it is used in the standalone pattern, for example, "MMMM", it gives the standalone form of a month name and when it is used in the pattern containing other field(s), for example, "d MMMM", it gives the format form of a month name. For example, January in the Catalan language is "de gener" in the format form while it is "gener" in the standalone form. In this case, "MMMM" will produce "gener" and the month part of the "d MMMM" will produce "de gener". If a DateFormatSymbols has been set explicitly with constructor SimpleDateFormat(String,DateFormatSymbols) or method setDateFormatSymbols(DateFormatSymbols), the month names given by the DateFormatSymbols are used.
🌐
Edureka
edureka.co › blog › date-format-in-java
Date Format In Java | Java Simple Date Format | Edureka
July 23, 2024 - In the next bit of this article on Date Format In Java, we will see how to create a simple date format, A SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. String pattern = "yyyy-MM-dd"; SimpleDateFormat simpleDateFormat = new SimpleDateFor...
🌐
Java2s
java2s.com › Tutorials › Java › Java_Date_Time › 0150__Java_Custom_Date_Format_Patterns.htm
Java Date Time - Custom Date Format Patterns
When defining custom date time format we can use symbols [ and ] to mark an optional section. A pattern enclosed within an optional section is output only if information is available for all its elements. The following code shows how to use an optional format. import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.Month; import java.time.format.DateTimeFormatter; /* w w w.
🌐
Joda
joda.org › joda-time › key_format.html
Joda-Time – Java date and time API - Formatting
The builder allows a format pattern to be built up step by step, consisting of literal, text, numeric, pattern and localized elements in any order. Some facilities are only available via the builder. For example, this will build a formatter consisting of the month and year: DateTimeFormatter monthAndYear = new DateTimeFormatterBuilder() .appendMonthOfYearText() .appendLiteral(' ') .appendYear(4, 4) .toFormatter();
🌐
InfluxData
influxdata.com › home › java date format: a detailed guide
Java Date Format: A Detailed Guide | InfluxData
July 12, 2024 - Java provides several ways to format dates, including usingSimpleDateFormat (which we covered in the subsequent sections) for custom patterns and DateTimeFormatter for more robust formatting options.
🌐
Qlik Talend Help
help.qlik.com › talend data preparation user guide › working with the data › cleansing dates › list of date and date/time formats
List of date and date/time formats | Talend Data Preparation User Guide Help
Locale-specific date and date/time formats are specified by date and time pattern strings. The following tables provide information on the patterns which are recognized as date or date/time data in Talend Data Preparation. According to the locale of your Java installation, the validation results ...
🌐
Baeldung
baeldung.com › home › java › java dates › a guide to simpledateformat
A Guide to SimpleDateFormat | Baeldung
January 8, 2024 - Let’s start with a dash-separated date pattern like so: ... This will correctly format a date starting with the current day of the month, current month of the year, and finally the current year. We can test our new formatter with a simple unit test.
🌐
iO Flood
ioflood.com › blog › java-simple-date-format
Java SimpleDateFormat Class: How-to Use with Examples
February 29, 2024 - Another common issue is dealing with different date and time patterns. The symbols used in the pattern strings are case-sensitive and each has a specific meaning. For example, ‘MM’ stands for month, ‘mm’ stands for minutes, ‘HH’ is for 24-hour format hour, and ‘hh’ is for 12-hour format hour. Ensure you are using the correct symbols for your desired output. Consult the Java documentation for a full list ...