⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e377. determining a person's age.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
This example uses the Calendar class to compute a person's age. 
    // Create a calendar object with the date of birth
    Calendar dateOfBirth = new GregorianCalendar(1972, Calendar.JANUARY, 27);
    
    // Create a calendar object with today's date
    Calendar today = Calendar.getInstance();
    
    // Get age based on year
    int age = today.get(Calendar.YEAR) - dateOfBirth.get(Calendar.YEAR);
    
    // Add the tentative age to the date of birth to get this year's birthday
    dateOfBirth.add(Calendar.YEAR, age);
    
    // If this year's birthday has not happened yet, subtract one from age
    if (today.before(dateOfBirth)) {
        age--;
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -