根据创建时间与当前时间比对时隔多少小时、分钟

                String KaiTaiShiJian = "";
                long hours = 0;//小时
                long fz = 0;//分钟
                if (null != v[13]) {
                    //当前时间
                    Date date = new Date();
                    String formatStr = "";
                    Date asd = null;
                    KaiTaiShiJian = v[13].toString();
                    String df = new SimpleDateFormat("yyy-MM-dd HH:mm:ss").format(date);
                    try {
                        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
                        asd = (Date) sdf.parse(KaiTaiShiJian);
                        formatStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(asd);
                        logger.info(formatStr);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    long diff = date.getTime() - asd.getTime();
                    long min = 0;//分钟
                    long day = 0;
                    long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
                    long nh = 1000 * 60 * 60;// 一小时的毫秒数
                    long nm = 1000 * 60;// 一分钟的毫秒数
                    day = diff / nd;// 计算差多少天
                    min = diff % nd % nh / nm + day * 24 * 60;// 计算差多少分钟

                    //小时
                    hours = diff / 60 / 60 / 1000;
                    //分钟
                    fz = min - day * 24 * 60;
                }
                int xs= Integer.valueOf((int) hours);
                int fenz= Integer.valueOf((int) fz);
                Format formatCount = new DecimalFormat("00");
                String shi = formatCount.format(xs);
                String fen = formatCount.format(fenz);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值