将毫秒转换成年月日时分秒
public static void main(String[] args) {
Date date = new Date();
System.out.println(date.getTime());
long a = date.getTime();
Date date1 = new Date(a);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String strdate = sdf.format(date1);
System.out.println(strdate);
}
比较两个时间的大小,字符串转换成时间日期类型
public static void main(String[] args) throws ParseException {
Date date = new Date();
String strdate = "2016-03-02 22:12:11";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date1 = format.parse(strdate);
if(date.getTime() > date1.getTime())
System.out.println("现在时间大");
else
System.out.println("字符串时间大");
}
当前时间加一天,计算时间相加相减
public static void main(String[] args) throws ParseException {
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
System.out.println("当前时间:"+sf.format(c.getTime()));
c.add(Calendar.DAY_OF_MONTH, 1);
System.out.println("增加一天后日期 : "+sf.format(c.getTime()));
}
mybatis中判断时间日期大小的sql
<![CDATA[ AND date_format(sud.endtime,‘%Y-%m-%d‘) >= date_format(NOW(),‘%Y-%m-%d‘) ]]>