• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

Java根据给定的日期计算其前一天和后一天的日期

JAVA相关 水墨上仙 1999次浏览

Java根据给定的日期计算其前一天和后一天的日期
转自:http://my.csdn.net/shenfuding_cn/code/detail/34403

package com.xtgd.test;
 
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Test {
 
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    System.in));
 
            System.out.println("请输入年份");
 
            String s1 = br.readLine();
 
            System.out.println("请输入月份");
 
            String s2 = br.readLine();
 
            System.out.println("请输入日份");
 
            String s3 = br.readLine();
 
            int year = Integer.parseInt(s1);
 
            int month = Integer.parseInt(s2);
 
            int day = Integer.parseInt(s3);
 
            if (year >= 0 && month >= 1 && month <= 12) {
 
                if (month == 1 || month == 3 || month == 5 || month == 7
 
                || month == 8 || month == 10 || month == 12) {
 
                    if (day >= 1 && day <= 31) {
 
                        System.out.println("您输入的日期为:" + year + "年" + month
                                + "月"
 
                                + day + "日");
 
                        if (day == 31) {
 
                            if (month == 12)
 
                                System.out.println("且上一天为:" + year + "年12月"
 
                                + (day - 1) + "日" + "," + "下一天为:"
 
                                + (year + 1) + "年1月1日");
 
                            else
 
                                System.out.println("且上一天为:" + year + "年"
                                        + month
 
                                        + "月" + (day - 1) + "日" + "," + "下一天为:"
 
                                        + year + "年" + (month + 1) + "月1日");
 
                        } else if (day == 1) {
 
                            if (month == 1)
 
                                System.out.println("且上一天为:" + (year - 1)
 
                                + "年12月31日" + "," + "下一天为:" + year + "年"
 
                                + month + "月" + (day + 1) + "日");
 
                            else if (month == 3) {
 
                                if ((year % 4 == 0 && year % 100 != 0)
 
                                || (year % 400 == 0))
 
                                    System.out.println("且上一天为:" + year
                                            + "年2月29日"
 
                                            + "," + "下一天为:" + year + "年"
                                            + month
 
                                            + "月" + (day + 1) + "日");
 
                                else
 
                                    System.out.println("且上一天为:" + year
                                            + "年2月28日"
 
                                            + "," + "下一天为:" + year + "年"
                                            + month
 
                                            + "月" + (day + 1) + "日");
 
                            } else
 
                                System.out.println("且上一天为:" + year + "年"
 
                                + (month - 1) + "月30日" + "," + "下一天为:"
 
                                + year + "年" + month + "月" + (day + 1)
 
                                + "日");
 
                        } else
 
                            System.out.println("且上一天为:" + year + "年" + month
                                    + "月"
 
                                    + (day - 1) + "日" + "," + "下一天为:" + year
                                    + "年"
 
                                    + month + "月" + (day + 1) + "日");
 
                    } else
 
                        System.out.println("您输入的日期不合法");
 
                } else if (month == 4 || month == 6 || month == 9
                        || month == 11) {
 
                    if (day >= 1 && day <= 30) {
 
                        System.out.println("您输入的日期为:" + year + "年" + month
                                + "月"
 
                                + day + "日");
 
                        if (day == 30)
 
                            System.out.println("且上一天为:" + year + "年" + month
                                    + "月"
 
                                    + (day - 1) + "日" + "," + "下一天为:" + year
                                    + "年"
 
                                    + (month + 1) + "月1日");
 
                        else if (day == 1)
 
                            System.out.println("且上一天为:" + year + "年"
                                    + (month - 1)
 
                                    + "月31日" + "," + "下一天为:" + year + "年"
                                    + month
 
                                    + (day + 1) + "日");
 
                        else
 
                            System.out.println("且上一天为:" + year + "年" + month
                                    + "月"
 
                                    + (day - 1) + "日" + "," + "下一天为:" + year
                                    + "年"
 
                                    + month + (day + 1) + "日");
 
                    } else
 
                        System.out.println("您输入的日期不合法");
 
                } else if ((year % 4 == 0 && year % 100 != 0)
                        || (year % 400 == 0)) {
 
                    if (day == 29)
 
                        System.out.println("您输入的日期为:" + year + "年" + month
                                + "月"
 
                                + day + "日" + "n" + "且上一天为:" + year + "年2月28日"
 
                                + "," + "下一天为:" + year + "年3月1日");
 
                    else {
 
                        if (day == 28)
 
                            System.out.println("您输入的日期为:" + year + "年" + month
 
                            + "月" + day + "日" + "n" + "且上一天为:" + year
 
                            + "年2月27日" + "," + "下一天为:" + year + "年2月29日");
 
                        else
 
                            System.out.println("您输入的日期不合法");
 
                    }
 
                }
 
            } else {
 
                System.out.println("您输入的日期不合法");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
 
}


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明Java根据给定的日期计算其前一天和后一天的日期
喜欢 (0)
加载中……