已封装在方法中
public static Map<String, String> ZeroTime() {
long timeStamp = System.currentTimeMillis();
long zero = timeStamp / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset();
long yzero = timeStamp / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset() - 24 * 60 * 60 * 1000;
SimpleDateFormat Spdate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//long时间戳转date
Date todayDate = new Date(zero);
Date yesterdayDate = new Date(yzero);
//date格式化为string
String today = Spdate.format(todayDate);
String yesterday = Spdate.format(yesterdayDate);
Map<String, String> map = new HashMap<>();
map.put("today", today);
map.put("yesterday", yesterday);
return map;
}
日期格式为字符串
2019-11-21 00:00:00
2019-11-20 00:00:00
当mybatis操作数据库时
数据库时间格式为datetime类型等可以直接传入使用