简体   繁体   中英

Convert date from yyyy-mm-dd to utc format

I have a date, "2015-06-08". I want convert it to "08 June 2015"

String oldDateString = "2015-06-08";
 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);

but this does not work correctly. It returns "08 January 2015". What have I done wrong?

Use yyyy-MM-dd insted yyyy-mm-dd because 'm' in lowercase is minutes. Documentation : link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM