题解 | #计算日期到天数转换#

计算日期到天数转换

https://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded

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

public class Main {
    public static void main(String[] args) throws ParseException {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String input = in.nextLine();
            String begin = input.split(" ")[0] + " 1 1";
            SimpleDateFormat format = new SimpleDateFormat("yyyy MM dd");
            Date date1 = format.parse(input);
            Date date2 = format.parse(begin);
            System.out.println((date1.getTime() - date2.getTime() + 1000 * 60 * 60 * 24) /
                               1000 / 60 / 60 / 24);
        }
    }
}

全部评论

相关推荐

CARLJOSEPH...:宝宝你戾气太大了
点赞 评论 收藏
分享
05-24 14:12
门头沟学院 Java
点赞 评论 收藏
分享
05-09 13:22
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务