阳光网驿-企业信息化交流平台【DTC零售连锁全渠道解决方案】

 找回密码
 注册

QQ登录

只需一步,快速开始

扫描二维码登录本站

手机号码,快捷登录

老司机
查看: 1490|回复: 0

[转帖] 计算时间差--工程模式

[复制链接]
  • TA的每日心情
    开心
    2012-3-7 10:15
  • 签到天数: 11 天

    [LV.3]偶尔看看II

    发表于 2012-2-4 11:26:34 | 显示全部楼层 |阅读模式
    df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
             * 获得系统的当前时间
             * @param dateFormate 时间格式
             * @return
             */
            public static String getCurTime(SimpleDateFormat dateFormate){
                    Date date = new Date(System.currentTimeMillis());
                    return dateFormate.format(date);

            }
            
            /**
             *
             * @param begin 开始时间
             * @param end  当前时间
             * @param dateFormate 时间格式
             * @return  两个时间点之间的差,单位小时
             */
            public static long compareTime(String begin,String end,SimpleDateFormat dateFormate){
                    long hours = 0;
                    try {
                            Date date1 = dateFormate.parse(begin);
                            Date date2 = dateFormate.parse(end);
                            long diff = date2.getTime() - date1.getTime();
    //                        int min= diff/(1000 * 60 ); //分钟
                            hours = diff/(1000 * 60* 60);//小时
                    } catch (ParseException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                    }
                   
                    return hours;
            }
    楼主热帖
    启用邀请码注册,提高发帖质量,建设交流社区
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    快速回复 返回顶部 返回列表