SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String date = sdf.format(new Date());
System.out.println(date); 结果是今天,即2014年3月23日
但当我做的时候
SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy"); 结果可以是23/05/2014,23/05/2014,23/06/2014和儿子与每次运行的prgram。为什么会这样呢?
发布于 2014-03-23 11:41:19
这是因为mm是几分钟,而不是几个月。更多在文献资料。
发布于 2014-03-23 11:51:08
在C#和VB.NET中,大小写很敏感,特别是对月份或分钟进行格式化。因为这两个单词的起始字符是相同的。
下面的详细信息可能有助于您格式化日期和时间。
1. d/D: day without 0 prefix on single digit.
2. dd/DD: day with 0 prefix if single digit.
3. M: Month without 0 prefix on single digit.
4. MM: Month with 0 prefix if single digit.
5. yy/YY: Last two digit of year.
6. yyyy/YYYY: represents full year.
7. HH: 24 hour based hour. ie. 13:00. **H** will display hour without prefix 0 if single digit
8. hh: 12 hour based hour. ie. 01:00. **h** will display hour without prefix 0 if single digit
9. m: minute without 0 prefix on single digit.
10.mm: minute with 0 prefix if single digit.
11.s: second without 0 prefix on single digit.
12.ss: second with 0 prefix if single digit.
13.tt: represent the AM or PM发布于 2014-03-23 11:41:43
mm表示分钟,所以当您使用mm时,它将打印分钟而不是月份。
而MM代表几个月。
阅读更多关于Time Patterns的信息
https://stackoverflow.com/questions/22590381
复制相似问题