提交 5c566093 authored 作者: 李炎's avatar 李炎

改时间戳判断bug

上级 bfc8a548
...@@ -111,12 +111,15 @@ public class WebApi { ...@@ -111,12 +111,15 @@ public class WebApi {
//检查ERM日期是否可用作过滤条件 //检查ERM日期是否可用作过滤条件
void checkRequest(SoSsRequestVo soSsRequestVo) { void checkRequest(SoSsRequestVo soSsRequestVo) {
System.out.println(soSsRequestVo.getStartTime());
// 时间字段检查 // 时间字段检查
if (null == soSsRequestVo.getStartTime() && null == soSsRequestVo.getEndTime()) { if (null == soSsRequestVo.getStartTime() && null == soSsRequestVo.getEndTime()) {
} else if (null == soSsRequestVo.getStartTime() || null == soSsRequestVo.getEndTime()) { } else if (null == soSsRequestVo.getStartTime() || null == soSsRequestVo.getEndTime()) {
throw new SoSsRequestException("操作失败!", "起止时间为空", "500"); throw new SoSsRequestException("操作失败!", "起止时间为空", "500");
} else if (StringUtil.isNumber(soSsRequestVo.getStartTime()) && StringUtil.isNumber(soSsRequestVo.getEndTime())) { } else if (StringUtil.isNumber(soSsRequestVo.getStartTime()) && StringUtil.isNumber(soSsRequestVo.getEndTime())) {
if (Integer.parseInt(soSsRequestVo.getStartTime()) > Integer.parseInt(soSsRequestVo.getEndTime()))
if (Long.parseLong(soSsRequestVo.getStartTime()) > Long.parseLong(soSsRequestVo.getEndTime()))
throw new SoSsRequestException("操作失败!", "开始时间大于结束时间", "500"); throw new SoSsRequestException("操作失败!", "开始时间大于结束时间", "500");
} else { } else {
throw new SoSsRequestException("操作失败!", "startTime以及endTime字段请使用 unix 时间戳填写,单位毫秒", "500"); throw new SoSsRequestException("操作失败!", "startTime以及endTime字段请使用 unix 时间戳填写,单位毫秒", "500");
......
...@@ -115,9 +115,14 @@ class JintaiDomeApplicationTests { ...@@ -115,9 +115,14 @@ class JintaiDomeApplicationTests {
@Test @Test
void asd() throws Exception { void asd() throws Exception {
System.out.println(TimeStamp2Date("1641398499000", "yyyy-MM-dd HH:mm:ss")); long i = Long.parseLong("1640966400000");
System.out.println(TimeStamp2Date("1609999999000", "yyyy-MM-dd HH:mm:ss")); // float v = Float.parseFloat("f");
System.out.println(""+new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date (1641398400000L)));
System.out.println(i);
// System.out.println(TimeStamp2Date("1641398499000", "yyyy-MM-dd HH:mm:ss"));
// System.out.println(TimeStamp2Date("1609999999000", "yyyy-MM-dd HH:mm:ss"));
// System.out.println(""+new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date (1641398400000L)));
} }
public static String TimeStamp2Date(String timestampString, String formats) { public static String TimeStamp2Date(String timestampString, String formats) {
...@@ -129,7 +134,30 @@ class JintaiDomeApplicationTests { ...@@ -129,7 +134,30 @@ class JintaiDomeApplicationTests {
String date = new SimpleDateFormat(formats, Locale.CHINA).format(new Date(timestamp)); String date = new SimpleDateFormat(formats, Locale.CHINA).format(new Date(timestamp));
return date; return date;
} }
@Test
public void testTimestamp(){
Date time = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
calendar.add(Calendar.HOUR,-1);
Date startTime = calendar.getTime();
calendar.add(Calendar.HOUR,2);
Date endTime = calendar.getTime();
System.out.println(time);
System.out.println(startTime);
System.out.println(endTime);
long timestamp = 1640966400000l;
long startTimestamp = startTime.getTime();
long endTimestamp = endTime.getTime();
System.out.println(timestamp);
System.out.println(startTimestamp);
System.out.println(endTimestamp);
System.out.println(timestamp>startTimestamp);
System.out.println(timestamp>endTimestamp);
}
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论