`
xrqsjj
  • 浏览: 20514 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

时间比较结果为HH:MM格式

    博客分类:
  • j2se
阅读更多

public static void main(String[] args)
    {
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String s ="2010-09-28 14:10:00";
        
        String e ="2010-09-28 15:11:00";
        try
        {
            System.out.println("e  = "+fmt.parse(e).getTime());
            
            System.out.println("s  = "+fmt.parse(s).getTime());
            
            long ss = (fmt.parse(e).getTime()- fmt.parse(s).getTime())/(60*1000);
            
            System.out.println("ss  = "+ss);
            
            DecimalFormat df1 = new DecimalFormat("0");
            double hh =Math.floor(ss/60);
            double mm =Math.floor(ss - hh*60);
            System.out.println("hh:mm  = "+df1.format(hh)+":"+df1.format(mm));
        }
        catch (ParseException e1)
        {
            e1.printStackTrace();
        }
       
    }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics