Home java How to translate a date from YYYY-MM-DD format to a generally accepted...

How to translate a date from YYYY-MM-DD format to a generally accepted view?




There is a date of the view “2015-05-15”. How to make the date of the species “May 15, 2015”?

Answer 1, Authority 100%

Using SimpleDateFormat (in order to “May” managed in Russian, it is necessary, respectively, 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);

Answer 2, Authority 64%

In addition to the above, I propose to use new classes from the java.time package, which appeared in Java 8, and not to use long-stayed java.util.date

string datestring = "2015-05-15";
LocalDate Date = LocalDate.Parse (DateString, dateTimeFormatter.Offattern ("Yyyy-Mm-DD"));
System.Out.PrintLN (date.format ("DD Mmmm Yyyy", New Locale ("RU"))));

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions