我正在计算直到足球比赛开始的时间量.
这就是我所知道的:
>我有时间参加活动:2016-08-16T19:45:00Z
>我知道它的字符串格式是“yyyy-M-dd’T’h:m:s’Z’”
>我知道时区是“CET”.
我希望能够计算从当前时间到此日期的差异.
这是我尝试过的:
String gameDate = "2016-03-19T19:45:00'Z'"
DateFormat apiFormat = new SimpleDateFormat("yyyy-M-dd'T'h:m:s'Z'");
apiFormat.setTimeZone(TimeZone.getTimeZone("CET"));
Date dateOfGame = apiFormat.parse(gameDate);
DateFormat currentDateFormat = new SimpleDateFormat("yyyy-M-dd'T'h:m:s'Z'");
currentDateFormat.setTimeZone(TimeZone.getTimeZone(userTimezone));
Date currentDate = apiFormat.parse(currentDateFormat.format(new Date()));
long lGameDate = dateOfGame.getTime();
long lcurrDate = currentDate.getTime();
long difference = lGameDate - lcurrDate;
Date timeDifference = new Date(difference);
String daysAway = new SimpleDateFormat("d").format(timeDifference);
Integer intDaysAway = Integer.parseInt(daysAway);
你可能想知道为什么我不只是得到游戏的日期(8)并减去当前的日期(19).我不会在当前日期是第29天且游戏日期是下个月的第3天的边缘情况下这样做.