JSONObject jo = new JSONObject();
jo.put("token", "0");
DateFormat df = DateFormat.getDateInstance();
Date endDate = new Date();
String endTime = df.format(endDate)+" 00:00:00";
jo.put("endTime", endTime);
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE, - 7);
Date startDate = c.getTime();
String startTime = df.format(startDate)+" 00:00:00";
jo.put("startTime", startTime);
jo.put("pageSize", 50);
jo.put("pageNo", 1);
System.out.println("____________________"+jo.toString());
本地使用这种方式格式化时间。输出格式如下
{"token":"0","endTime":"2017-4-26 00:00:00","startTime":"2017-4-19 00:00:00","pageSize":50,"pageNo":1}
发布到linux服务器上,时间变成这样的
{"token":"0","endTime":"Apr 26, 2017 00:00:00","startTime":"Apr 19, 2017 00:00:00","pageSize":50,"pageNo":1}
时间格式不一样了,因为后面要用做post请求的,所以格式必须是上面 yyyy-MM-dd HH:mm:ss 这种格式的,但是同样的class上传到服务器上,就变成那种了
我的哥,你的实现怎么整这么麻烦啊
SimpleDateFormate simpleDateFormate = new SimpleDateFormate("yyyy-MM-dd HH:mm:ss");
jo.put("endTime",simpleDateFormate.formate(new Date(System.currentMills()-7*24*3600*1000)));//可以将new Date这种获取指定日期之前之后的封装到DateUtil中
jo.put("startTime",simpleDateFormate.formate(new Date(System.currentMills())));
纯手打,可能会出现拼写错误
不是代码的问题,是操作系统不同导致的
直接用SimpleDateFormate转换好,然后再用,操作系统不同它转换的时间格式也是不一样的呀,,你先拿SimpleDateFormate统一一下,再试试