如何在java中将日期格式从YYMMDD更改为YYYY-MM-DD? [英] How to change the date format from YYMMDD to YYYY-MM-DD in java?
本文介绍了如何在java中将日期格式从YYMMDD更改为YYYY-MM-DD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从机器可读代码中获取日期格式为YYMMDD,如何将其更改为YYYY-MM-DD?
例如我得到871223(YYMMDD)
我将魔杖变成1987-12-23(YYYY-MM-DD)
有可能吗?
有人可以帮我提供一些示例代码吗?
I am getting the date format from the machine readable code as YYMMDD, how can i change it into YYYY-MM-DD ? for example am getting 871223(YYMMDD) i wand to change it into 1987-12-23(YYYY-MM-DD) is it possible ? can anyone help me with some sample codes?
推荐答案
代码如下:
SimpleDateFormat fromUser = new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
String reformattedStr = myFormat.format(fromUser.parse(inputString));
} catch (ParseException e) {
e.printStackTrace();
}
这篇关于如何在java中将日期格式从YYMMDD更改为YYYY-MM-DD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文