我想今年转换转换SimpleDateFormat的一年整数
SimpleDateFormat actualYear = new SimpleDateFormat("yyyy");
在整型变量。
谢谢你!
我想今年转换转换SimpleDateFormat的一年整数
SimpleDateFormat actualYear = new SimpleDateFormat("yyyy");
在整型变量。
谢谢你!
如果你想从year string
,这是yyyy格式int year
,
int year = Integer.parseInt("2014");
如果你想从current year
int year
,
int year = Calendar.getInstance().get(Calendar.YEAR);
如果您想从date object
得到int year
,
String yearString = new SimpleDateFormat("yyyy").format(date);
int year = Integer.parseInt(yearString);
SimpleDateFormat
对象只是格式化Date
对象到字符串中。除非您要求格式化日期,否则它实际上并没有意识到日期。下面的例子将打印一年2015
SimpleDateFormat format = new SimpleDateFormat("yyyy");
String formattedDate = format.format(new Date());
int year = Integer.parseInt(formattedDate);
System.out.println(year);
是否要将'actualYear'转换为整数?你有没有尝试'Integer.parseInt(actualYear);'? –
这是说“方法parseInt没有任何方法接收简单的日期格式” –