java 日期比较

package com.dao;

import java.util.Date;
import java.util.Calendar;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class SystemTime
{
    public static void main(String[] args)
    {   Calendar rightNow = Calendar.getInstance();
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String sysDatetime = fmt.format(rightNow.getTime());
        Calendar cal=Calendar.getInstance();
        //-200代表200天前这个时候的时间
        cal.add(Calendar.DAY_OF_YEAR,-3);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String nowtime=sdf.format(cal.getTime());
        System.out.println(nowtime);
        DateFormat   df   =   new   SimpleDateFormat();
       
        try {
System.out.println(sdf.parse(nowtime).getTime()<sdf.parse(sysDatetime).getTime());

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
       

    }
}

你可能感兴趣的:(java,DAO)