Java-判断某日期为该年的第几天

版权声明:知识无界限,大家可自由转载。 https://blog.csdn.net/xidianbaby/article/details/84995344
public static void main(String[] args) {
        //2017-12-13
        String str = "12-13";
        //2017年每个月的天数
        List<Integer> dayOfMon = Arrays.asList(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
        int month = Integer.parseInt(str.split("-")[0]);
        int day = Integer.parseInt(str.split("-")[1]);
        int result = (month - 1) * dayOfMon.get(month - 1) + day;
        System.out.println(str + " is the " + result + "th day of this year.");
        }

猜你喜欢

转载自blog.csdn.net/xidianbaby/article/details/84995344