java date与日期转换操作

date 已经废弃使用

package imooc.chap01.vl.date;

import java.util.Date;

public class test1 {
    public static void main(String[] args) throws InterruptedException {
        Date currentTime = new Date();
        Thread.sleep(3000);
        Date newTime =new Date();
        long msDelay=newTime.getTime()- currentTime.getTime();
        System.out.println(msDelay);
    }
}

package imooc.chap01.vl.date;

import java.util.Date;

public class test2 {
    public static void main(String[] args) throws InterruptedException {
        Date startTime = new Date();
        long endTime=startTime.getTime()+5000;
        Date enddate = new Date(endTime);
        Thread.sleep(3000);

        Date currentTime = new Date();
        //检查 currentTime 是否在 endDate 之后
        if (currentTime.after(enddate)){
            System.out.println("结束时间!");
        }
    }
}

package imooc.chap01.vl.date;

import java.util.Date;

public class test3 {
    public static void main(String[] args) {
        Date currentTime = new Date();
        int hours = currentTime.getHours();
        int minutes = currentTime.getMinutes();
        int seconds = currentTime.getSeconds();
        System.out.println(hours+":"+minutes+":"+seconds);



    }
}

package imooc.chap01.vl.date;

import java.time.Year;
import java.util.Date;

public class test4 {
    public static void main(String[] args) throws Exception{
        Date yearStartTime = new Date();
        yearStartTime.setHours(0);
        yearStartTime.setMinutes(0);
        yearStartTime.setSeconds(0);
        yearStartTime.setDate(1);
        yearStartTime.setMonth(0);
        Date currentTime=new Date();
        long msTimeDifference=currentTime.getTime()- yearStartTime.getTime();
        long msDay=24*60*60*1000;
        int dayCount=(int) (msTimeDifference/msDay);
        System.out.println(dayCount);
    }
}

日期转换Locale.ENGLISH表示用英文显示,MMM几个表示显示几位

package zh.codegym.task.task09.task0922;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/* 
今天是几号?
*/

public class Solution {

    public static void main(String[] args) throws Exception {
        //在此编写你的代码
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd",Locale.ENGLISH);
        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("MMM dd, yyyy",Locale.ENGLISH);
        Date parse = simpleDateFormat.parse(reader.readLine());
        System.out.println(simpleDateFormat1.format(parse).toUpperCase(Locale.ROOT));


    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

金融小白数据分析之路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值