宝宝百岁生日计算器

  • Post author:
  • Post category:其他


宝宝百岁生日计算器



宝宝百岁生日计算器

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * @author DELL
 */
public class Test01 {
    public static void main(String[] args) throws ParseException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入宝宝出生日期:");
        String str = sc.nextLine();
        System.out.println("宝宝百岁日期:" + get100YearDate(str));

    }

    static String get100YearDate(String birthday) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = sdf.parse(birthday);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_YEAR, 100);
        return sdf.format(calendar.getTime());
    }
}



版权声明:本文为weixin_38882971原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。