Created
August 12, 2018 13:32
-
-
Save mstrYoda/2b3c975428f488358a9099a841577647 to your computer and use it in GitHub Desktop.
Java LocalDate and Date example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws IOException, ParseException { | |
String str = "Sun Jun 10 05:23:03 2018"; | |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE MMM d HH:mm:ss yyyy"); | |
System.out.println(LocalDate.parse(str, formatter)); | |
DateFormat fmt = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.ENGLISH); | |
DateFormat targetFormat = new SimpleDateFormat("dd-MM-yyyy"); | |
Date date = fmt.parse(str); | |
System.out.println(date); | |
System.out.println(targetFormat.format(date)); | |
} | |
/* | |
Outputs : | |
// date time formatter | |
2018-06-10 | |
// simple date format | |
Sun Jun 10 05:23:03 EET 2018 | |
10-06-2018 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment