求以前某个日期是星期几的java代码

求以前某个日期是星期几的java代码

/*
 * Copyright (c) 2021, 2023, xwdl All rights reserved.
 *
 */
package demo;

import java.util.Calendar;
import java.util.Date;

/**
 * <p>Project: untitled - Time</p>
 * <p>Powered by xwdl On 2023-07-06 19:25:06</p>
 * <p>描述:<p>
 *
 * @author xwdl []
 * @version 1.0
 * @since 17
 */
public class Time {
    public static void main(String[] args) {
        int i = new Date().getHours();
        //int i = 9;Select files to commit
        if (6 <= i && i < 8) {
            System.out.println("早上好");
        } else if (8 <= i && i < 12) {
            System.out.println("上午好");
        } else if (12 <= i && i < 14) {
            System.out.println("中午好");
        } else if (14 <= i && i < 20) {
            System.out.println("下午好");
        } else if (20 <= i && i < 23) {
            System.out.println("晚上好");
        } else {
            System.out.println("凌晨好");//RandomDraw
        }
        System.out.println("----------------");
        long time = System.currentTimeMillis();//获取当前的时间戳
        Calendar c = Calendar.getInstance();
        c.set(1989, 9, 15);//设置指定时间,
        long c1 = c.getTimeInMillis();
        long a = (time - c1) / (1000 * 60 * 60 * 24);
        System.out.printf("%tY年%<tm月%<td日到%tY年%<tm月%<td日,共有%d天%n", c1, time, a);
        System.out.println("--------------");

        //计算5天前的日期
        long a1 = time - 1000 * 60 * 60 * 24 * 5;
        System.out.printf("当前时间为%tY年%<tm月%<td日5天前的时间为%tY年%<tm月%<td日%n", time, a1);
        long a2 = time + 1000 * 60 * 60 * 24 * 10;
        System.out.printf("当前时间为%tY年%<tm月%<td日10天后的时间为%tY年%<tm月%<td日%n", time, a2);
        System.out.println("_______________");
        c.set(2008, 4, 12);//
        long q = c.getTimeInMillis();
        c.set(2023, 6, 7);//确定一个已经知道星期的日期,2023.7.7周五;
        long q1 = c.getTimeInMillis();
        long q2 = System.currentTimeMillis();
        long x = (q2 - (q2 - q1) - q) % 7;
        if (x == 0) {
            System.out.printf("今天是%tY年%<tm月%<td日,", q2);
            System.out.println("2008-5-12是星期五");
        } else if (x == 1) {
            System.out.printf("今天是%tY年%<tm月%<td日,", q2);
            System.out.println("2008-5-12是星期四");
        } else if (x == 2) {
            System.out.printf("今天是%tY年%<tm月%<td日,", q2);
            System.out.println("2008-5-12是星期三");
        } else if (x == 3) {
            System.out.printf("今天是%tY年%<tm月%<td日,", q2);
            System.out.println("2008-5-12是星期二");
        } else if (x == 4) {
            System.out.printf("今天是%tY年%<tm月%<td日,", q2);
            System.out.println("2008-5-12是星期一");
        } else if (x == 5) {
            System.out.printf("今天是%tY年%<tm月%<td日,", q2);
            System.out.println("2008-5-12是星期日");
        } else {
            System.out.printf("今天是%tY年%<tm月%<td日,", q2);
            System.out.println("2008-5-12是星期六");

        }

    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值