I have a Zulu time "2011-08-12T20:17:46.384Z". How can i extract date part using java joda time? I have read multiple question on Zulu Time but none answer my question.
-
Did you check [Converting a date string to a DateTime object using Joda Time](https://stackoverflow.com/questions/6252678/converting-a-date-string-to-a-datetime-object-using-joda-time-library) ? – Eklavya Oct 16 '20 at 18:54
-
For Java 8 and later use the new built in api – Thorbjørn Ravn Andersen Oct 16 '20 at 19:06
-
Which new API ? – p0s0731 Oct 16 '20 at 19:09
-
1[This API: java.time (Oracle tutorial)](https://docs.oracle.com/javase/tutorial/datetime/TOC.html). It’s 6 and a half years old and considered the modern Java date and time API and the successor of Joda-Time. Even though it isn’t brand new, to me it still feels that way, in a very good way. I warmly recommend it. – Ole V.V. Oct 16 '20 at 20:10
-
Do you want the date in your time zone or the date in UTC (Zulu)? – Ole V.V. Oct 16 '20 at 20:11
-
@pritisharma - If one of the answers resolved your issue, you can help the community by marking that as accepted. An accepted answer helps future visitors use the solution confidently. – Arvind Kumar Avinash Oct 22 '20 at 20:20
2 Answers
Do you want the date in your own time zone or in Zulu (UTC)? Asking because it is never the same date in all time zones.
Date in Zulu time zone, the same date as in the string, is the easier requirement:
String zuluString = "2011-08-12T20:17:46.384Z";
DateTime dt = DateTime.parse(zuluString);
LocalDate datePart = dt.toLocalDate();
System.out.println(datePart);
Output:
2011-08-12
Getting the date in the default time zone of the JVM just requires a few chars more:
LocalDate datePart = dt.withZone(DateTimeZone.getDefault()).toLocalDate();
Output when run in Asia/Macau time zone:
2011-08-13
Which new API ?
Joda-Time is in maintenance mode and no longer recommended for new code. The Joda-Time home page says:
Note that Joda-Time is considered to be a largely “finished” project. No major enhancements are planned. If using Java SE 8, please migrate to
java.time
(JSR-310).
java.time is built into Java since Java 8 and has also been backported to Java 6 and 7. You may start by following the second link below.
Links
- Joda-Time - Home
- Oracle tutorial: Date Time explaining how to use java.time.

- 81,772
- 15
- 137
- 161
I suggest you switch to the modern date-time API.
Using the modern java.time (JSR-310)
API:
import java.time.LocalDate;
import java.time.OffsetDateTime;
public class Main {
public static void main(String[] args) {
OffsetDateTime odt = OffsetDateTime.parse("2011-08-12T20:17:46.384Z");
System.out.println(odt);
LocalDate date = odt.toLocalDate();
System.out.println(date);
}
}
Output:
2011-08-12T20:17:46.384Z
2011-08-12
Learn more about the modern date-time API at Trail: Date Time.
Check out the following lines from the home page of Joda-Time documentation:
Joda-Time is the de facto standard date and time library for Java prior to Java SE 8. Users are now asked to migrate to java.time (JSR-310).
Using the Joda-Time API:
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
public class Main {
public static void main(String[] args) {
DateTime dateTime = DateTime.parse("2011-08-12T20:17:46.384Z");
System.out.println(dateTime);
LocalDate date = dateTime.toLocalDate();
System.out.println(date);
}
}
Output:
2011-08-12T20:17:46.384Z
2011-08-12

- 71,965
- 6
- 74
- 110