0
我试图计算一个API返回给我的时间和当前设备时间之间的差异。剩余时间计算android总是一个小时错
的API返回的时间格式为: “game_start”: “2015年9月3日19:00:00”
要计算我做到这一点的区别:
protected String getTimeToStart(JSONObject jsonObject) {
String time = "";
Calendar startTime;
Calendar current;
startTime = Calendar.getInstance();
current = Calendar.getInstance();
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat format2 = new SimpleDateFormat("HH mm ");
startTime.setTime(format.parse(jsonObject.getJSONObject("data").getJSONObject("game").getString("game_start")));
String[] splited = (format2.format(startTime.getTimeInMillis() - current.getTimeInMillis()).split("\\s+"));
time = splited[0] + "hrs " + splited[1] + "mins";
} catch (ParseException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
if (checkStarted(startTime, current)) {
return time;
} else {
return "League Started";
}
protected boolean checkStarted(Calendar start, Calendar current) {
if (current.before(start)) {
return true;
} else {
return false;
}
}
这个问题我有的是,计算总是将剩余的时间返回为应该是的一个小时,直到它达到它实际上开始的时间,然后它返回没有剩余时间,例如
当前时间= 16时59 时间它开始于= 17时 剩余时间时返回1hrs 1mins
然后
当前时间= 17时 时间它开始于= 17: 00 剩余的时间返回联盟已开始