java程序计算游戏时间_Java计算从当前时间到事件的时间

我正在尝试计算直到足球比赛开始为止的时间。

这是我所知道的:

我有活动时间: 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号的情况下,我不这样做。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值