Java Calendar获取年.月.日.时间 Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00")); //获取东八区时间 int year = c.get(Calendar.YEAR); //获取年 int month = c.get(Calendar.MONTH) + 1; //获取月份,0表示1月份 int day = c.get(Calendar.DAY_OF_MONTH);
Date d = new Date(); System.out.println(d); //Sat Mar 16 20:58:56 CST 2019 System.out.println(d.toLocaleString());//2019-3-16 20:59:38 System.out.println(new SimpleDateFormat("yyyy-MM-dd ahh:mm:ss").format(d));//2019-3-16 下午20:59:38 当使用 toLocale
Date ruZhi = new Date("入职年月bai"); Date now = new Date(); //算出du来时间夸格zhi多长 long shiChang = now.getTime()-now.getTIme(); //转换成天 int day = shiChang/(1000*60*24); //转换成想要dao的格式,这里zhuan定为1年=365天 1月=30天 //算出年 int year =day/365; day = day%365; //算出月 in