在Java中获取当前年份的整数值 [英] Get integer value of the current year in Java
本文介绍了在Java中获取当前年份的整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将Java当前年份确定为整数。我想使用这个值作为一个计数器,例如,我可以使用从现在开始运行到过去的特定年份(即我的值从2008开始,我有一个firstYearOfData值,我现在可以从2008年开始到1994年)。我可以使用java.util.Date(),但不推荐使用。
I need to determine the current year in Java as an integer. I would like to be able to use this value as a counter that I can, for example, use to run from now until a specified year in the past (i.e. my value starts at 2008, and I have a "firstYearOfData" value that is set to 1994. I can now run my process from 2008 back to 1994). I could just use java.util.Date(), but it is deprecated.
推荐答案
int year = Calendar.getInstance().get(Calendar.YEAR);
不知道是否满足不设置新日历的条件? (为什么反对这样做?)
Not sure if this meets with the criteria of not setting up a new Calendar? (Why the opposition to doing so?)
这篇关于在Java中获取当前年份的整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文