简体   繁体   中英

Is there any java library to check if given Date meets criteria given in String?

Im looking for a java library that can check if given Date meets criteria given in string, for eg.:

  • YYYY.MM.DD - specific day, eg. 2002.04.01.
  • YYYY.MM.DD-YYYY.MM.DD - days in range, eg. 2002.02.01-2002.11.20.
  • DD - day of month, eg. 04 (fourth day of every month).
  • DD-DD - range of days in month, eg. 04-15 (from fourth to fifteenth day o every month)
  • DAY - day of week, possible values: MON, TUE, WED, THU, FRI, SAT, SUN.
  • DAY-DAY - range of days in week, eg. MON-FRI (working days).
  • HH24:MI-HH24:MI - time range with minute precision, eg. 02:15-17:30.

Interface should look like:

public boolean checkDate(Date testDate, String criteria);

Java itself has rich Date and calendar API, you can check various examples on google.

here is one of them, http://www.vogella.de/articles/JavaDateTimeAPI/article.html

Also check Calendar API http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Calendar.html

For Date API check http://docs.oracle.com/javase/1.5.0/docs/api/java/sql/Date.html

我可以将内置的SimpleDateFormat与日历一起使用,也可以使用JodaTime。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM