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天的边缘情况下这样做.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值