简体   繁体   English

将日期从 yyyy-mm-dd 转换为 utc 格式

[英]Convert date from yyyy-mm-dd to utc format

I have a date, "2015-06-08".我有一个日期,“2015-06-08”。 I want convert it to "08 June 2015"我想将其转换为“2015 年 6 月 8 日”

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".它返回“2015 年 1 月 8 日”。 What have I done wrong?我做错了什么?

Use yyyy-MM-dd insted yyyy-mm-dd because 'm' in lowercase is minutes.使用yyyy-MM-dd insted yyyy-mm-dd因为小写的 'm' 是分钟。 Documentation : link文档: 链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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