I have a variable in my Java class that needs to be set based on whether today is before or after 7/1. If today is before 7/1 then we are in fiscal year that is the current year (so today we are in FY10). If today is after 7/1 our new fiscal year has started and the variable needs to be the next year (so FY11).
psuedo code:
if today < 7/1/anyyear then
BudgetCode = "1" + thisYear(YY) //variable will be 110
else
BudgetCode = "1" + nextYear(YY) //开发者_如何学Pythonvariable will be 111
thanks!
Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH, Calendar.JULY);
cal.set(Calendar.DATE, 1);
if (cal.after(someDate)) {
fy = cal.get(Calendar.YEAR) + 1;
}
else {
fy = cal.get(Calendar.YEAR);
}
I think the if statement would be like this to get the 2 digit year with the "1" digit on the front end of it.
if (cal.after(someDate)) {
BudgetCode = "1".concat(new Integer(cal.get(Calendar.YEAR)%100).toString());
}
else {
BudgetCode = "1".concat(new Integer(cal.get(Calendar.YEAR)%100).toString());
}
精彩评论