• 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
  • 相关阅读:
    8位二进制cpu的设计和制作
    MySQL数据库管理
    算法拾遗十六二叉树相关算法
    天软特色因子看板(2023.10 第12期)
    扬帆际海—shopee跨境店和本土店谁更有优势?
    Hive(16):Hive调优之HQL语法优化
    KMP算法(C++)
    上位机模块之halcon绘制ROI与获取ROI,在hsmartwindow实现
    LVS-DR模式
    Vue项目流程8,导航守卫的使用,图片懒加载,利用vee-validate实现表单验证,路由懒加载,打包并处理map文件
  • 原文地址:https://blog.csdn.net/weixin_45631815/article/details/126327960