SimpleDateFormat不正确处理DD [英] SimpleDateFormat does not process DD properly
本文介绍了SimpleDateFormat不正确处理DD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获得如下格式:
I am trying to get a format like this:
2013-06-15-17-45
我在代码中执行以下操作:
I do the following in my code:
Date d = new Date();
SimpleDateFormat ft = new SimpleDateFormat ("YYYY_MM_DD_HH_mm");
String fileName = "D:\\"+ft.format(d)+".csv";
但是我没有得到DD权限。它创建一个名称如下的文件:
But I don't get the DD right. It creates a file with a name like this:
D:\\2013_12_340_13_53.csv
推荐答案
资本D是年的一天;小写字母d是月的日期( SimpleDateFormat
javadocs )。尝试:
Capital "D" is day of year; lowercase "d" is day of month (SimpleDateFormat
javadocs). Try:
SimpleDateFormat ft = new SimpleDateFormat ("yyyy_MM_dd_HH_mm");
此外,资本Y是周年;通常使用小写y(年)。
Also, capital "Y" is "week year"; usually lowercase "y" ("year") is used.
这篇关于SimpleDateFormat不正确处理DD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文