在.property中存储日期并与当前日期进行比较

1 java date

如何将未来日期存储在.property文件中,并将此日期与当前日期进行比较?

hel*_*ios 8

你可以:

  1. 保存格式化的日期
  2. 如果你愿意,也可以保存格式,增加灵活性

属性文件:

myDate=25/01/2012
myDate.pattern=dd/MM/yyyy
Run Code Online (Sandbox Code Playgroud)

然后,在您的程序中,您可以这样加载日期:

// 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);
Run Code Online (Sandbox Code Playgroud)

编辑:与当前比较......

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
Run Code Online (Sandbox Code Playgroud)