• 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);
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    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("结束时间!");
            }
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    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);
    
    
    
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    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);
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    日期转换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));
    
    
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
  • 相关阅读:
    新一代网络框架UringNet,基于最新的异步I/O
    Python学习第3天:变量与数据类型
    中国书画院院士、著名画家——戴友
    QT_C++_多线程
    Transformer中Relative Position Bias以及DropPath细节梳理
    刷爆 LeetCode 双周赛 100,单方面宣布第一题最难
    手搭手zabbix5.0监控redis7
    Redis 只会用缓存?20种妙用让同事直呼牛X(荣耀典藏版)
    D. Xenia and Colorful Gems(二分+暴力)
    SSH详解
  • 原文地址:https://blog.csdn.net/weixin_45631815/article/details/126327960