Calculate age from BirthDate

后端 未结 17 1401
攒了一身酷
攒了一身酷 2021-02-07 08:33

I have DatePicker Dialog, When I select date at that time I want to calculate age it\'s working but when I select date of current year at that time it showing the -1 age instead

17条回答
  •  一个人的身影
    2021-02-07 08:59

    static int calculateAge(int birthdayDay, int birthdayMonth, int birthdayYear)
    {
        DateTime date = DateTime(birthdayYear, birthdayMonth, birthdayDay).toLocal();
        DateTime now = DateTime.now().toLocal();
    
        return now.difference(date).inDays ~/ 365.2425;
    }
    

提交回复
热议问题