This question already has answers here:
Change date format in a Java string
(22 answers)
Closed 4 years ago.
I am new to Java. I am trying to convert date from string to MMM yyyy format (Mar 2016). I tried this
Calendar cal=Calendar.getInstance();
SimpleDateFormat month_date = new SimpleDateFormat("MMM yyyy");
String month_name = month_date.format(cal.getTime());
System.out.println("Month :: " + month_name); //Mar 2016
It is working fine. But when I use
String actualDate = "2016-03-20";
It is not working. Help me, how to solve this.
Your format must match your input
for 2016-03-20
the format should be (just use a second SimpleDateFormat object)
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Full answer
SimpleDateFormat month_date = new SimpleDateFormat("MMM yyyy", Locale.ENGLISH);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String actualDate = "2016-03-20";
Date date = sdf.parse(actualDate);
String month_name = month_date.format(date);
System.out.println("Month :" + month_name); //Mar 2016
Using java.time java-8
String actualDate = "2016-03-20";
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH);
DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("MMM yyyy", Locale.ENGLISH);
DateTimeFormatter dtf3 = DateTimeFormatter.ofPattern("MMMM yyyy", Locale.ENGLISH);
LocalDate ld = LocalDate.parse(actualDate, dtf);
String month_name = dtf2.format(ld);
System.out.println(month_name); // Mar 2016
String fullMonthAndYear = dtf3.format(ld);
System.out.println(fullMonthAndYear); // March 2016
Try this code:
DateFormat df = new SimpleDateFormat("dd-MMMM HH:mm a");
Date date = new Date(System.currentTimeMillis());
String infi = df.format(date);
And the output should be:
11-May 4:47 PM
tl;dr
YearMonth.from(
LocalDate.parse( "2016-03-20" )
)
.format(
DateTimeFormatter.ofPattern(
"MMM uuuu" ,
Locale.US
)
)
Mar 2016
java.time
Avoid the troublesome old date-time classes. Entirely supplanted by the java.time classes.
YearMonth
Java has a class to represent a year and month. Oddly named, YearMonth.
LocalDate ld = LocalDate.parse( "2016-03-20" ) ;
YearMonth ym = YearMonth.from( ld ) ;
Define a formatting pattern for your desired output.
Specify a Locale. A Locale determines (a) the human language for translation of name of day, name of month, and such, and (b) the cultural norms deciding issues of abbreviation, capitalization, punctuation, separators, and such.
DateTimeFormatter f = DateTimeFormatter.ofPattern( "MMM uuuu" , Locale.US ) ;
String output = ym.format( f ) ;
Mar 2016
You could use that formatter on the LocalDate. But I assume you may have further need of the year-month as a concept, and so the YearMonth class may be useful.
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for java.sql.* classes.
Where to obtain the java.time classes?
Java SE 8, Java SE 9, Java SE 10, and later
Built-in.
Part of the standard Java API with a bundled implementation.
Java 9 adds some minor features and fixes.
Java SE 6 and Java SE 7
Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
Android
Later versions of Android bundle implementations of the java.time classes.
For earlier Android (<26), the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). See How to use ThreeTenABP….
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.
Related
thanks.
system default locale difference.
SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy h:mm:ss a", Locale.ENGLISH);
get solved.
String to Date Error
String : Feb 13, 2017 10:25:43 AM
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy h:mm:ss a");
or MMM d, yyyy h:mm:ss a, MMM d, yyyy hh:mm:ss a, MMM dd, yyyy h:mm:ss a, MMM dd, yyyy hh:mm:ss a, MMM dd, yyyy H:mm:ss a, MMM dd, yyyy HH:mm:ss a
...etc
ParseException ::::: Unparseable date: "Feb 13, 2017 10:25:43 AM"
plz help.
tl;dr
LocalDateTime.parse(
"Feb 13, 2017 10:25:43 AM" ,
DateTimeFormatter.ofPattern( "MMM d, uuuu hh:mm:ss a" , Locale.US )
)
2017-02-13T10:25:43
java.time
You are using troublesome old date-time classes that are now legacy, supplanted by the java.time classes.
Specify a formatting pattern to match your input. Note that we pass a Locale to specify the human language and cultural norms used in translating name of month and such.
String input = "Feb 13, 2017 10:25:43 AM" ;
DateTimeFormatter f = DateTimeFormatter.ofPattern( "MMM d, uuuu hh:mm:ss a" , Locale.US ) ;
Your input string lacks any indicator of time zone or offset-from-UTC. So parse as a LocalDateTime.
LocalDateTime ldt = LocalDateTime.parse( input , f );
ldt.toString(): 2017-02-13T10:25:43
By the way, if your input had had a comma after the year, you could have parsed using an automatically localized formatter rather than bothering to define a formatting pattern. That comma is apparently the norm for the United States (at least).
String input = "Feb 13, 2017, 10:25:43 AM" ; // With a comma after year, apparently the norm in the United States.
DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime( FormatStyle.MEDIUM ).withLocale( Locale.US )
LocalDateTime ldt = LocalDateTime.parse( input , f );
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for java.sql.* classes.
Where to obtain the java.time classes?
Java SE 8, Java SE 9, and later
Built-in.
Part of the standard Java API with a bundled implementation.
Java 9 adds some minor features and fixes.
Java SE 6 and Java SE 7
Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
Android
Later versions of Android bundle implementations of the java.time classes.
For earlier Android, the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). See How to use ThreeTenABP….
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.
I have a String in format "YYYY-MM-dd" and i want convert this into "MMM dd, yyyy" format.
I used bellow code to do this;
But when i convert "2014-11-18" the output is this "Sun Dec 29 00:00:00 IST 2013"
How can I solve this?
DateFormat target=new SimpleDateFormat("MMM dd, yyyy");
String P_date="2014-11-18"
Date test1 = new SimpleDateFormat("YYYY-MM-dd").parse(P_date);
String converted_date=target.format(test1);
Date test=target.parse(converted_date);
The y (lowercase Y) format means "year". Y (uppercase Y) you were using means "WeekYear".
Just use y and you should be OK:
DateFormat target=new SimpleDateFormat("MMM dd, yyyy");
String P_date="2014-11-18";
Date test1 = new SimpleDateFormat("yyyy-MM-dd").parse(P_date);
String converted_date=target.format(test1);
Date test=target.parse(converted_date);
Y returns Week year that's why you are seeing week day too. use y instead.
Date test1 = new SimpleDateFormat("yyyy-MM-dd").parse(P_date);
You can write like this
final JDateChooser startDateChooser = new JDateChooser();
startDateChooser.setDateFormatString("yyyy-MM-dd");
Date startDate = startDateChooser.getDate();
HashMap listMap = new HashMap();
listMap.put("Start Period is ", ((startDate.getYear() + 1900)+ "-" + (startDate.getMonth() + 1) + "-" +startDate.getDate()));
tl;dr
LocalDate.parse( "2014-11-18" ).format( // Parse string as `LocalDate` object, then generate a string in a certain format.
DateTimeFormatter.ofLocalizedDate( FormatStyle.MEDIUM )
.withLocale( Locale.US ) // Automatically localize to a locale’s human language and cultural norms.
) // Returns a String.
Details
The accepted Answer by Mureinik is correct, your formatting pattern used codes incorrectly.
Another issue is that you are interested in a date-only value, but you are using a date-with-time type.
Also, you are using troublesome old date-time classes that are now supplanted by the java.time classes.
java.time
Your YYYY-MM-DD format complies with ISO 8601 format. The java.time classes use those standard formats by default when parsing/generating strings. So no need to specify a formatting pattern.
LocalDate ld = LocalDate.parse( "2014-11-18" ) ;
To generate a string in other formats, use the DateTimeFormatter or DateTimeFormatterBuilder classes.
You could specify a hard-coded formatting pattern. But better to soft-code by letting java.time automatically localize. To localize, specify:
FormatStyle to determine how long or abbreviated should the string be.
Locale to determine (a) the human language for translation of name of day, name of month, and such, and (b) the cultural norms deciding issues of abbreviation, capitalization, punctuation, separators, and such.
Example:
Locale l = Locale.US ; // Or Locale.CANADA_FRENCH, Locale.ITALY, etc.
DateTimeFormatter f = DateTimeFormatter.ofLocalizedDate( FormatStyle.MEDIUM ).withLocale( l );
String output = zdt.format( f );
Nov 18, 2014
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
With a JDBC driver complying with JDBC 4.2 or later, you may exchange java.time objects directly with your database. No need for strings or java.sql.* classes.
Where to obtain the java.time classes?
Java SE 8, Java SE 9, and later
Built-in.
Part of the standard Java API with a bundled implementation.
Java 9 adds some minor features and fixes.
Java SE 6 and Java SE 7
Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
Android
Later versions of Android bundle implementations of the java.time classes.
For earlier Android, the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). See How to use ThreeTenABP….
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.
I want to parse a date into my format like 02:09 AM 25/09/2012 but I can't. I used this code.
SimpleDateFormat sdf1 = new SimpleDateFormat("MMMM, DD yyyy HH:mm:ss Z");
//September, 25 2012 02:09:42 +0000
Date date = sdf1.parse(String.valueOf(PUNCH_TIME));
SimpleDateFormat sdf2 = new SimpleDateFormat("HH':'mm a 'on' DD'/'MMMM'/'yyyy");
SimpleDateFormat sdf2 = new SimpleDateFormat("MM");
String timeformat=sdf2.format(date);
txtHomePunchStatus.setText("You have Punched In at "+timeformat);
and I got You have punched IN at 7:52 AM on 25/01/2012.
You probably have issues with the time zone. The input string September, 25 2012 02:09:42 +0000 is a timestamp in UTC (offset +0000). When you format your date in the desired format, you're not specifying a time zone, so the SimpleDateFormat object is going to show your date in your local time zone, which is probably not UTC.
What you can do is set the time zone on the SimpleDateFormat object that you use to format the date. For example:
DateFormat df1 = new SimpleDateFormat("MMMM, dd yyyy HH:mm:ss Z");
Date date = df1.parse(PUNCH_TIME);
DateFormat df2 = new SimpleDateFormat("HH:mm a 'on' dd/MM/yyyy");
df2.setTimeZone(TimeZone.getTimeZone("UTC"));
String result = df2.format(date);
System.out.println(result);
Note: You must use dd and not DD for the days; DD means day number of the year, dd means day number in the month (see the API documentation of SimpleDateFormat).
p.s.: Your usage of the words "parse" and "format" is confusing. Parsing means: converting from a string to a Date object, and formatting means the opposite: converting from a Date object to a string.
First off you have a double declaration of sdf2. Then, you need to use hh and mm for hours and minutes. Read the documentation: SimpleDateFormat Like in this example:
SimpleDateFormat sdf1 = new SimpleDateFormat("MMMM, DD yyyy HH:mm:ss Z");
//September, 25 2012 02:09:42 +0000
Date date = null;
try {
date = sdf1.parse(String.valueOf(PUNCH_TIME));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SimpleDateFormat sdf2 = new SimpleDateFormat("hh:mm a 'on' DD/MM/yyyy");
String timeformat=sdf2.format(date);
tl;dr
OffsetDateTime.parse(
"September, 25 2012 02:09:42 +0000" ,
DateTimeFormatter.ofPattern( "MMMM, d uuuu HH:mm:ss Z" , Locale.US )
).format(
DateTimeFormatter.ofPattern( "hh:mm a 'on' dd/MM/uuuu" , Locale.US )
)
02:09 AM on 25/09/2012
Avoid legacy date-time classes
The other Answers are now outmoded, using troublesome old date-time classes that are now legacy. The old classes are supplanted by the java.time classes. For earlier Android, see the last bullets below.
java.time
Define a formatting pattern to match your input string.
String input = "September, 25 2012 02:09:42 +0000" ;
DateTimeFormatter f = DateTimeFormatter.ofPattern( "MMMM, d uuuu HH:mm:ss Z" , Locale.US ) ; // Specify a locale for the human language by which to parse the name of the month.
Parse as an OffsetDateTime given that your input specifies an offset-from-UTC but not a full time zone.
OffsetDateTime odt = OffsetDateTime odt = OffsetDateTime.parse( input , f );
odt.toString(): 2012-09-25T02:09:42Z
To generate a string in an alternate format, define a DateTimeFormatter with a custom formatting pattern. Pay attention to the uppercase/lowercase of your formatting code characters, and study closely the documentation. Note that colons, spaces, and slashes are known by the formatter, so no need to escape those characters with the single-quote marks.
DateTimeFormatter fOutput = DateTimeFormatter.ofPattern( "hh:mm a 'on' dd/MM/uuuu" , Locale.US ) ;
String output = odt.format( fOutput) ;
02:09 AM on 25/09/2012
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
Java SE 8, Java SE 9, and later
Built-in.
Part of the standard Java API with a bundled implementation.
Java 9 adds some minor features and fixes.
Java SE 6 and Java SE 7
Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
Android
Later versions of Android bundle implementations of the java.time classes.
For earlier Android, the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). See How to use ThreeTenABP….
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.
I am trying to parse datetime string with SimpleDateFormat.parse() but I keep receiving Unparseable date exceptions.
Here is the date format I am trying to parse: 2011-10-06T12:00:00-08:00
Here is the code I am using:
try {
String dateStr = "2011-10-06T12:00:00-08:00";
SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
SimpleDateFormat dateFormatter = new SimpleDateFormat("MMM d, yyyy");
Date date = dateParser.parse(dateStr);
System.out.println(dateFormatter.format(date));
} catch(Exception e) {
System.out.println(e.getMessage());
}
Which returns this error: java.text.ParseException: Unparseable date: "2011-10-06T12:00:00-08:00"
As far as I know this is the correct way to use the SimpleDateFormat class but I'm not fluent in Java so I could be mistaken. Any one know what my issue is?
The timezone should be GMT-08:00 or -0800 (as Madcore Tom said). See Java docs.
In Java 7 you can use "yyyy-MM-dd'T'HH:mm:ssX"
I believe that SimpleDateFormat will not parse timezones with a colon in them (-08:00). It should be able to parse the date 2011-10-06T12:00:00-0800.
Some simple string manipulation should help you get rid of the colon.
You first need to format the value in "2011-10-06T12: 00: 00-08: 00".
Example: SimpleDateFormat dateParser = new SimpleDateFormat ("yyyy-MM-dd'T'HH: mm: ssZ");
After, create the formating for formataction desired.
Ex: SimpleDateFormat fmt = new SimpleDateFormat ("dd / MM / yyyy HH: mm: ss");
and after make parse for date.
Ex: Date date = dateParser.parse (dateFormat);
and print of date formated.
Below, one complete example.
String dataStr = "2011-10-06T12: 00: 00-08: 00";
SimpleDateFormat dataParser = new SimpleDateFormat ("dd / MM / yyyy HH: mm: ss", Locale.US);
Date date;
Try {
date = dataParser.parse (dataStr);
System.out.println (dateFormatter.format (date));
} cath (ParseException e) {
}
tl;dr
OffsetDateTime.parse( "2011-10-06T12:00:00-08:00" )
.format(
DateTimeFormatter.ofLocalizedDate( FormatStyle.MEDIUM ).withLocale( Locale.US ) // Or Locale.CANADA_FRENCH and such.
)
Oct 6, 2011
java.time
The modern approach uses the java.time classes that supplant the troublesome old legacy date-time classes.
You input string is in a format that complies with the ISO 8106 standard. The java.time classes use these standard formats by default when parsing/generating strings. So no need to specify a formatting pattern.
Parse as an OffsetDateTime because your input strings includes an offset-from-UTC but not a time zone.
OffsetDateTime odt = OffsetDateTime.parse( "2011-10-06T12:00:00-08:00" ) ;
odt.toString(): 2011-10-06T12:00-08:00
Generate a string in your desired format. Let java.time automatically localize rather than hard-code formatting patterns.
DateTimeFormatter f = DateTimeFormatter.ofLocalizedDate( FormatStyle.MEDIUM ).withLocale( Locale.US ); // Or Locale.CANADA_FRENCH and such.
String output = odt.format( f );
output: Oct 6, 2011
When seralizing a date-time value as text, use the standard ISO 8601 formats rather than a localized format.
String output = odt.toLocalDate().toString() ;
2011-10-06
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
Java SE 8, Java SE 9, and later
Built-in.
Part of the standard Java API with a bundled implementation.
Java 9 adds some minor features and fixes.
Java SE 6 and Java SE 7
Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
Android
Later versions of Android bundle implementations of the java.time classes.
For earlier Android, the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). See How to use ThreeTenABP….
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.
Try with
SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
For a date format like 2013-06-28T00:00:00+00:00, this code should work:
SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
I am sure most of you got frustrated from the fact that SimpleDateFormat can not handle ISO8601 format. Here is my little trick to solve this nuisance.
Create a list of Know format you know that you will use for your application and apply SimpleDateFormat to the list. Now, in your formatDate() method, simple try all your known format and trap the Exception, then if still did not have a date, just use
Date d = javax.xml.bind.DatatypeConverter.parseDateTime("2013-06-28T00:00:00+00:00").getTime();
if (d == null)
try {
SimpleDateFormater ...
}
to try it and see if that work. For more info Simple trick to convert Date format with timezone in Java!
I'd strongly recommend using JodaTime for this sort of thing.
You're trying to parse an ISO Date format, and Joda does that 'out of the box', and will give you plenty of other benefits too.
I long ago gave up trying to get the standard JDK data classes to do helpful things.
I want to convert date from MM/YYYY to MM/DD/YYYY, how i can do this using SimpleDateFormat in Java? (Note: DD can be start date of that month)
please go through the http://download.oracle.com/javase/1.5.0/docs/api/java/text/DateFormat.html following link for more clarity.
One way of implementation i have in my mind is :
String yourDate = <yourDate>
DateFormat dateFormat= new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Date date= new Date();
date = (Date)dateFormat.parse(yourDate);
//String dateString= dateFormat.format(date);
/*Print your date*/
Please go through this link SimpleDateFormat
try {
String str_date = "01/11";
DateFormat formatter;
Date date;
formatter = new SimpleDateFormat("MM/yyyy");
date = (Date) formatter.parse(str_date);
formatter = new SimpleDateFormat("MM/dd/yyyy");
System.out.println("Today is " + formatter.format(date));
} catch (ParseException e) {
System.out.println("Exception :" + e);
}
The simplest approach is using string manipulation.
String date1 = "12/2010";
String date2 = date1.replace("/","/01/");
tl;dr
YearMonth.parse(
"12/2016" ,
DateTimeFormatter.ofPattern( "MM/uuuu" ) )
)
.atDay( 1 )
.format( DateTimeFormatter.ofPattern( "MM/dd/uuuu" ) ) // 12/01/2016
java.time
Java now includes the YearMonth class to represent exactly this kind of value, a month and a year without a day-of-month.
The default format for parsing/generating strings of a month-year is YYYY-MM. That format is defined as part of the ISO 8601 format. The java.time classes use ISO 8601 formats by default.
Your input string has alternate format so we must specify a formatting pattern.
String input = "12/2016" ; // December 2016.
DateTimeFormatter f = DateTimeFormatter.ofPattern( "MM/uuuu" );
YearMonth ym = YearMonth.parse( input , f );
See the results by calling toString.
String output = ym.toString();
2016-12
Specify a day-of-month to create a LocalDate instance. The LocalDate class represents a date-only value without time-of-day and without time zone.
LocalDate ld = ym.atDay( 1 );
You can let the class figure out the last day of the month. Remember that February varies in length for Leap Year. The YearMonth class knows how to handle Leap Year.
LocalDate ld = ym.atEndOfMonth();
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
Java SE 8 and SE 9 and later
Built-in.
Part of the standard Java API with a bundled implementation.
Java 9 adds some minor features and fixes.
Java SE 6 and SE 7
Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
Android
The ThreeTenABP project adapts ThreeTen-Backport (mentioned above) for Android specifically.
See How to use ThreeTenABP….
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.
FYI, Java has a similar class, MonthDay.