How do I convert a date from the yyyy-mm-dd format to the standard format?
There is a date of the form "2015-05-15". How do I make a date like "May 15, 2015"out of it?
6
2 answers
Using SimpleDateFormat
(to get" may " in Russian, you need, respectively, the locale). Example:
String oldDateString = "2015-05-15";
SimpleDateFormat oldDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
SimpleDateFormat newDateFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.getDefault());
Date date = oldDateFormat.parse(oldDateString);
String result = newDateFormat.format(date);
14
Author: katso, 2016-06-12 10:12:16
In addition to the above, I suggest using the new classes from the java.time package, which appeared in Java 8, and not using the long-outdated java. util. Date
String dateString = "2015-05-15";
LocalDate date = LocalDate.parse(dateString, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
System.out.println(date.format(DateTimeFormatter.ofPattern("dd MMMM yyyy", new Locale("ru"))));
9
Author: zzashpaupat, 2015-05-15 09:47:49