909422229

xiaoxiao2021-02-28  194

一、如何比较昨天时间小于今天时间:

昨天时间:dateA

今天时间:dateB

利用:Calendar ca = Calendar.getInstance();

long value = (dateA.getTime() - dateB.getTime()) / 1000 / 60 / 60 / 24;

返回值:如果大于0则说明dateA > dateB

二、时间格式转换:

     在使用SimpleDateFormat时格式化时间的 yyyy.MM.dd 为年月日而如果希望格式化时间为12小时制的,则使用hh:mm:ss 如果希望格式化时间为        24小时制的,则使用HH:mm:ss。

 

        Date d = new Date();  

        SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//12小时制  

        System.out.println(ss.format(d));  

        Date date = new Date();  

        SimpleDateFormat sdformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//24小时制  

//日期转date格式化时间类型:

        String LgTime = sdformat.format(date);  

        System.out.println(LgTime);  

        //String日期转date类型:

Date currentTime_2 = formatter.parse(dateString);

System.out.println(currentTime_2);

转载请注明原文地址: https://www.6miu.com/read-23142.html

最新回复(0)