2

i want to change Russian Date to US format

String rDate = "28 августа 2017";

output :

String usDate = "28-08-2017";
  • 1
    You need to show your attempt at solving the problem so we can help you. – atomskaze Dec 31 '19 at 17:27
  • Try following. https://stackoverflow.com/questions/59546926/how-to-convert-russian-date-format-to-us-date-format#comment105262910_59546926 – G Shenoy Dec 31 '19 at 18:05
  • 1
    @atomskaze Actually, that is not always the case. The founders of Stack Overflow intended this site to be knowledge base, not a workshop. Some types of questions need an attempt at code, some do not. This one does not. – Basil Bourque Dec 31 '19 at 19:25

1 Answers1

2

You can use DateTimeFormatter with withLocale.

Parsing text.

DateTimeFormatter dateTimeFormatter = 
    DateTimeFormatter
    .ofPattern("dd MMMM uuuu")
    .withLocale( new Locale("ru") )
;
LocalDate ld = LocalDate.parse(rDate, dateTimeFormatter);

Generating text.

String usDate = ld.format(DateTimeFormatter.ofPattern("dd-MM-uuuu"));
=> 28-08-2017

See this code run live at IdeOne.com.

Basil Bourque
  • 262,936
  • 84
  • 758
  • 1,028
YCF_L
  • 51,266
  • 13
  • 85
  • 129