将当前年份值设置为整数

时间:2015-12-15 05:33:07

标签: java

我想将当前年份的值设为:

"1" if year is 2015
"2" if year is 2016

等等。有可能吗?

int year = Calendar.getInstance().get(Calendar.YEAR);

使用这种方法给了我2015年的年份,但我希望将它等同于1或2,依此类推。

2 个答案:

答案 0 :(得分:2)

不知道在2015年之前你想要怎样处理任何事情,但是现在就去:

int year = Calendar.getInstance().get(Calendar.YEAR) - 2014;

答案 1 :(得分:0)

int year = Calendar.getInstance().get(Calendar.YEAR) % 2014;

也有效