無線&移動互聯網技術研發

          換位思考·····
          posts - 19, comments - 53, trackbacks - 0, articles - 283
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          日歷

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          我參與的團隊

          最新隨筆

          搜索

          •  

          積分與排名

          • 積分 - 358323
          • 排名 - 155

          求兩個時間差

          Posted on 2009-05-20 19:09 Gavin.lee 閱讀(829) 評論(0)  編輯  收藏 所屬分類: Date tools

          按照測試方法,就能夠算出兩個時間點的差。

          package com.Gavin.tools.util;

          import java.util.Date;
          import java.text.ParseException;
          import java.text.SimpleDateFormat;

          import com.sun.org.apache.bcel.internal.generic.NEW;

          /** *//**
           * Title: 日期時間
           * Description: 工具類
           * 
          @author Gavin.lee
           * @date 09-05-4 9-14am
           * 
          @version 1.0
           
          */

          public class DateUtil {

              
          public static String date2Dispersion(String date_front, String date_back) {
                  SimpleDateFormat df 
          = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                  Date begin 
          = null;
                  Date end 
          = null;
                  
          try {
                      begin 
          = df.parse(date_front);
                      end 
          = df.parse(date_back);
                  }
           catch (ParseException e) {
                      e.printStackTrace();
                  }


                  
          long between = (end.getTime() - begin.getTime()) / 1000;// 除以1000是為了轉換成秒
                  long day = between / (24 * 3600);//
                  long hour = between % (24 * 3600/ 3600;//小時
                  long minute = between % 3600 / 60;//分鐘
                  long second = between % 60 / 60;//

                  
          return day + "" + hour + "小時" + minute + "分鐘" + second + "";
              }

              
              
          public static void main(String args[]) {
                  System.out.println(DateUtil.date2Dispersion(
          "2004-01-02 11:30:24""2004-03-26 13:31:40"));
              }

          }

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 和龙市| 肇庆市| 鄂伦春自治旗| 平阳县| 水城县| 嘉禾县| 呼图壁县| 临猗县| 襄樊市| 北碚区| 兰坪| 光泽县| 兴宁市| 马山县| 玉树县| 永胜县| 米林县| 平罗县| 宕昌县| 惠水县| 化州市| 沙洋县| 龙州县| 慈利县| 九江市| 饶阳县| 清远市| 鹤岗市| 封开县| 安平县| 广东省| 汉川市| 河曲县| 胶州市| 天津市| 齐齐哈尔市| 德格县| 罗甸县| 金塔县| 临海市| 磐石市|