从日历中减去? [英] Subtraction from calendar ?

查看:74
本文介绍了从日历中减去?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public int yearWorked(){

int totalWorked =
    GregorianCalendar.getInstance(YEAR) - this.hiringDate.get(Calendar.YEAR); // is this logic correct ?

return totalWorked;
}



我想计算员工工作的年数。所以我想要的是从当前日期和当前员工做一个简单的减法,但我的语法是错误的:(


I want to calculate the years that an employee has worked. So what i am trying is to make a simple subtraction from current date and the current employee ,but my syntax is wrong :(

推荐答案

试试这个:

Try this:
GregorianCalendar today = new GregorianCalendar();
int totalWorked = today.get(Calendar.YEAR) - hiringDate.get(Calendar.YEAR);



hiringDate 也必须是 GregorianCalendar 的实例。


这篇关于从日历中减去?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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