gpt4 book ai didi

java - 比较日期Java格式问题

转载 作者:行者123 更新时间:2023-11-29 03:57:22 25 4
gpt4 key购买 nike

尝试在 java 中比较一些日期但无法正确设置格式,我哪里出错了?

DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
Date date1 = null, date2 = null, today = new Date();
date1 = (Date) df.parse(scan.next());

System.out.println(date1);
System.out.println(today);
if(date1.compareTo(today) < 0){
date1 = null;
System.out.println(start + " is not a valid date.. please try again!");
}

Please enter a start date:
10/04/2011
Mon Jan 10 00:04:00 GMT 2011
Tue Apr 05 22:27:44 BST 2011

最佳答案

我认为你需要MM,而不是mm

来自 the doc :

M Month in year
m Minute in hour

关于java - 比较日期Java格式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5558788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com