Unix时间戳转java.util.Date,以及日期函数date_sub()

来源:互联网 发布:2016知乎年度吐槽 编辑:程序博客网 时间:2024/06/06 05:09

1.unix时间戳转时间

这里是10位的,如果是13位的去掉*1000就可以了

public static Date unixTimeToDate(int unixTime) throws ParseException{        SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        Long time=new Long(unixTime)*1000;          String d = format.format(time);        return format.parse(d);   }


Date time = DateUtil.unixTimeToDate(nonCarInsuranceOrder.getCreateTime());

========================================================================================
2. mysql数据库 LOCALTIMESTAMP(now()) 为13位时间戳, UNIX_TIMESTAMP(now()) 为10位时间戳。

LOCALTIMESTAMP(now())一般为ms,UNIX_TIMESTAMP(now())一般为s


========================================================================================

3.date_sub()函数+unix时间转换函数,查询6个月以内订单

o.createTime  BETWEEN unix_timestamp(date_format(DATE_SUB(CURRENT_DATE (), INTERVAL 6 MONTH),'%Y-%m-%d 00:00:00')) AND unix_timestamp(date_format(current_date(),'%Y-%m-%d 00:00:00'))







阅读全文
0 0
原创粉丝点击