在.property中存储日期并与当前日期进行比较 [英] Storing a date in .property and comparing with current date
本文介绍了在.property中存储日期并与当前日期进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将未来日期存储在.property文件中,并将此日期与当前日期进行比较?
How do I store a future date in a .property file and compare this date with current the current date?
推荐答案
您可以:
- 保存格式化日期
- 如果需要,另存为格式,添加灵活性
属性文件:
myDate=25/01/2012
myDate.pattern=dd/MM/yyyy
然后,在你的程序中,你可以这样加载日期:
Then, in your program you could load the date this way:
// 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);
修改:比较当前的...
Edit: to compare to current...
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
这篇关于在.property中存储日期并与当前日期进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文