java编程中,如何实现时间的计算?

[复制链接]
查看11 | 回复2 | 2012-2-15 13:49:20 | 显示全部楼层 |阅读模式
得到当前的时间 Date date = new Date();如果要计算 2个时间的差 比如 2012-12-21 离 现在还有多少天 ?long a = date.getTime();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");long b = sdf.parse("2012-12-21").getTime();int success = (int) ((b-a)/(1000*60*60*24));//1000毫秒*60分钟*60秒*24小时 = 天System.out.println("距离2012-12-21还有"+success+"天");...
回复

使用道具 举报

千问 | 2012-2-15 13:49:20 | 显示全部楼层
正解...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行