当前位置:编程学习 > JAVA >>

java 时间大小的比较

Java代码 
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.Calendar;  
import java.util.Date;  
 
public class A {  
    public static void main(String[] args) throws ParseException{  
        Date d1 = Calendar.getInstance().getTime();  
        String s1 = new SimpleDateFormat("yyyy"+"-"+"MM"+"-"+"dd HH" + ":" + "mm" + ":" + "ss").format(d1);  
        System.out.println("s1==="+stb1);  
          
        String time = "2011-08-13 14:42:43";  
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
        Date dd= sdf.parse(time.toString());  
        String ss = new SimpleDateFormat("yyyy"+"-"+"MM"+"-"+"dd HH" + ":" + "mm" + ":" + "ss").format(dd);  
        System.out.println("ss==="+ss);  
          
        int i = d1.compareTo(dd);  
        if(i<0){  
            System.out.println("d1更早");  
        }else if(i==0){  
            System.out.println("d1一样");  
        }else{  
            System.out.println("dd更早");  
        }  
          
    }  

作者:tbwshc
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,