mysql datetime型別,java查詢時比較
阿新 • • 發佈:2019-02-02
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String startTimeStr="1483203661";
String endTimeStr="1496700366";
Long starTimesStamp = new Long(Integer.parseInt(startTimeStr)); Long endTimesStamp = new Long(Integer.parseInt(endTimeStr)); Date star = new Date(starTimesStamp*1000); Date end = newDate(endTimesStamp*1000); Pager pager = new Pager(); pager.getQuery().put("startTime",sdf.format(star)); pager.getQuery().put("endTime", sdf.format(end));
List<OrderInfo> orderInfoList = orderWebService.findOrderInfoByPager(pager).getData();
public List<OrderInfo> findOrderInfoByPager(Pager pager) throwsParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); List<Criterion> criterionList = new ArrayList<Criterion>(); String startTime = (String) pager.getQuery().get("startTime"); String endTime = (String) pager.getQuery().get("endTime"); if (StringUtils.isNotEmpty(startTime)){ Date start = sdf.parse(startTime); criterionList.add(Restrictions.gt("updated", start)); } if (StringUtils.isNotEmpty(endTime)){ Date end = sdf.parse(endTime); criterionList.add(Restrictions.lt("updated", end)); } Criterion[] criterions = new Criterion[criterionList.size()]; criterionList.toArray(criterions); List<OrderInfo> list = this.getDao().load(criterions); return list; }