Home  >  Q&A  >  body text

java - 新手求教,当前时间问题?

代码如下:

SimpleDateFormat std = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
System.out.println(std.format(new Date()));

为什么输出之后是2017-11-24 10:11:28, 2017-13-24 10:13:27.....等等之类的,好奇怪

每运行一次加一个月

完整代码:

巴扎黑巴扎黑2743 days ago592

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-04-18 10:53:47

    yyyy-mm-dd is changed to yyyy-MM-dd, which is capital letters!!! Capital letters indicate the month!!!

    reply
    0
  • PHPz

    PHPz2017-04-18 10:53:47

    yyyy is the complete Western Year, MM (capital) is the month, and dd is the date. As for hh:mm:ss, why are some formats uppercase and some lowercase? That’s to avoid confusion. For example, MM is the month and mm is the date. Minutes; HH is a 24-hour clock, and hh is a 12-hour clock

    reply
    0
  • PHPz

    PHPz2017-04-18 10:53:47

    The lowercase m represents minutes, so it will change every minute, just change it to an uppercase M

    reply
    0
  • Cancelreply