如何在 .property 文件中存储 future 日期并将此日期与当前日期进行比较?
最佳答案
你可以:
- 保存格式化的日期
- 如果需要,也可以保存格式,增加灵 active
属性文件:
myDate=25/01/2012
myDate.pattern=dd/MM/yyyy
然后,在您的程序中您可以这样加载日期:
// choose one of two lines!
String pattern = "dd/MM/yyyy"; // for a fixed format
String pattern = propertyFile.getProperty("myDate.pattern");
String formattedDate = propertyFile.getProperty("myDate");
SimpleDateFormat format = new SimpleDateFormat(pattern);
Date myDate = format.parse(formattedDate);
编辑:与当前...进行比较
1. boolean isFuture = myDate.after(new Date())
2. boolean isPast = myDate.before(new Date())
3. int compare = myDate.compareTo(new Date());
// compare < 0 => before
// compare == 0 => equal
// compare > 0 => after
关于java - 在 .property 中存储日期并与当前日期进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3243954/