在 Java 中获取当前年份的整数值 [英] Get integer value of the current year in Java

查看:28
本文介绍了在 Java 中获取当前年份的整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 Java 中的当前年份确定为整数.我可以只使用 java.util.Date(),但它已被弃用.

I need to determine the current year in Java as an integer. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆