国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務(wù)器之家 - 編程語言 - Java教程 - JAVA 根據(jù)身份證計(jì)算年齡的實(shí)現(xiàn)代碼

JAVA 根據(jù)身份證計(jì)算年齡的實(shí)現(xiàn)代碼

2021-04-28 11:06HrlSnow Java教程

這篇文章主要介紹了JAVA 根據(jù)身份證計(jì)算年齡的實(shí)例代碼及java根據(jù)出生日期獲得年齡的方法,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

下面一段代碼給大家分享java根據(jù)身份證計(jì)算年齡的方法,具體代碼如下所示:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
birthdate = idcard.substring(6,10)+"-"+idcard.substring(10,12)+"-"+idcard.substring(12,14)
public static int getagefrombirthtime(string birthtimestring){
 // 先截取到字符串中的年、月、日
 string strs[] = birthtimestring.trim().split("-");
 int selectyear = integer.parseint(strs[0]);
 int selectmonth = integer.parseint(strs[1]);
 int selectday = integer.parseint(strs[2]);
 // 得到當(dāng)前時(shí)間的年、月、日
 calendar cal = calendar.getinstance();
 int yearnow = cal.get(calendar.year);
 int monthnow = cal.get(calendar.month) + 1;
 int daynow = cal.get(calendar.date);
 // 用當(dāng)前年月日減去生日年月日
 int yearminus = yearnow - selectyear;
 int monthminus = monthnow - selectmonth;
 int dayminus = daynow - selectday;
 int age = yearminus;
 if (yearminus < 0) {// 選了未來的年份
  age = 0;
 } else if (yearminus == 0) {// 同年的,要么為1,要么為0
  if (monthminus < 0) {// 選了未來的月份
   age = 0;
  } else if (monthminus == 0) {// 同月份的
   if (dayminus < 0) {// 選了未來的日期
    age = 0;
   } else if (dayminus >= 0) {
    age = 1;
   }
  } else if (monthminus > 0) {
   age = 1;
  }
 } else if (yearminus > 0) {
  if (monthminus < 0) {// 當(dāng)前月>生日月
  } else if (monthminus == 0) {// 同月份的,再根據(jù)日期計(jì)算年齡
   if (dayminus < 0) {
   } else if (dayminus >= 0) {
    age = age + 1;
   }
  } else if (monthminus > 0) {
   age = age + 1;
  }
 }
 return age;
}

下面在看下java根據(jù)出生日期獲得年齡

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public static int getage(date birthday) throws exception {
  calendar cal = calendar.getinstance();
  if (cal.before(birthday)) {
   throw new illegalargumentexception(
    "the birthday is before now.it's unbelievable!");
  }
  int yearnow = cal.get(calendar.year);
  int monthnow = cal.get(calendar.month);
  int dayofmonthnow = cal.get(calendar.day_of_month);
  cal.settime(birthday);
  int yearbirth = cal.get(calendar.year);
  int monthbirth = cal.get(calendar.month);
  int dayofmonthbirth = cal.get(calendar.day_of_month);
  int age = yearnow - yearbirth;
  if (monthnow <= monthbirth) {
   if (monthnow == monthbirth) {
    if (dayofmonthnow < dayofmonthbirth) age--;
   }else{
    age--;
   }
  }
  system.out.println("age:"+age);
  return age;
 }

總結(jié)

以上所述是小編給大家介紹的java 根據(jù)身份證計(jì)算年齡,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)服務(wù)器之家網(wǎng)站的支持!

原文鏈接:https://blog.csdn.net/HrlSnow/article/details/80266906

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 久久久www成人免费无遮挡大片 | 免费观看的黄色 | 欧美污污 | 在线观看一级黄色片 | 国产精品成人在线 | 国产精品99久久 | 91精品国产一区二区三区 | 精品日韩一区二区三区 | 亚洲av毛片一区二二区三三区 | 国产福利视频 | 免费观看在线午夜影视 | 国产精品久久久爽爽爽麻豆色哟哟 | 一区二区日韩 | 毛片在线免费 | 亚洲一区视频在线 | 国产精品成av人在线视午夜片 | 欧美日韩精品久久久免费观看 | 日韩福利视频 | 国产毛片在线 | 麻豆产精国品免费 | 婷婷激情综合 | 毛片在线视频 | 色视频在线播放 | 国产精品免费看片 | 国产精品久久久久久久久久东京 | 国产在线乱 | www伊人| 亚洲福利在线播放 | 99在线播放 | 成人久久久 | 国产第一亚洲 | 色婷婷中文字幕 | 国产激情久久久久久 | 免费一级 国产 | 国产精品亚洲精品 | 台湾一级特黄aa大片免费看 | 一级毛片免费看 | av在线一区二区三区 | 欧美黑人一级爽快片淫片高清 | 午夜成人免费电影 | 欧美一级片在线播放 |