signed

QiShunwang

“诚信为本、客户至上”

java输出100天以后的日期和星期

2021/3/21 8:28:13   来源:
import java.util.Calendar;

public class Test {
    public static void main(String[] args) {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH,100);
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH) + 1;
        int day = c.get(Calendar.DAY_OF_MONTH);
        int week = c.get(Calendar.DAY_OF_WEEK);
        System.out.println("一百天后:" + year + "-" +  month + "-" + day + "-" + getWeek(week));

    }
    public static String getWeek(int week){
        String[] arr = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
        return arr[week - 1];
    }
}