Android 获取当前系统时间,并计算时间差

本文介绍了如何在Android平台上获取当前系统时间,并详细讲解了如何计算两个时间点之间的差值,包括具体步骤和调用的方法。
摘要由CSDN通过智能技术生成

1.获取系统当前时间

 DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 Date date = new Date(System.currentTimeMillis());
 String logindate1 = simpleDateFormat.format(date);
//存入时间
 MySp.putString(LoginActivity.this, "logindate1", logindate1);

2.计算时间差

private void TimeCompare(String date1, String date2) {
        long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
        long nh = 1000 * 60 * 60;// 一小时的毫秒数
        long nm = 1000 * 60;// 一分钟的毫秒数
        long ns = 1000;// 一秒钟的毫秒数
        //格式化时间
        DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String date1 = "2015-01-25 09:12:09";
//        String date2 = "2015-01-29 09:12:11";
        try {
            Date beginTime = simpleDateFormat.parse(date1);
            Date endTime = simpleDateFormat.parse(date2);
        
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值