unix "date --date=..." in Java
I there a way to instantiate a Date object any date represe开发者_如何学运维ntation in Java with input similar to the Unix
date --date='...'
that can figure out things like yesterday, tomorrow, next thursday etc?
I've tried to search this on Google, but it doesn't come up with anything related, as it's quite hard to explain what I'm looking for.
EDIT probably it was misleading, I don't want a suggestion on how to create a method myself, I'm looking for a working library/code.
EDIT 2 having in mind that PHP strtotime
does exactly the same thing, I searched and this time it gave me a great suggestion and I'm probably gonna stick to it.
You can create a util method using Calendar
for example :
public enum DateUtilKeyWords{
YESTERDAY;
}
public static Date getDate(DateUtilKeyWords dateUtilKeyWord) {
Calendar cal = Calendar.getInstance();
switch (dateUtilKeyWord) {
case YESTERDAY: {
cal.add(Calendar.DATE, -1);
break;
}
}
return cal.getTime();
}
精彩评论