国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

用Java做時間的減法

2019-11-18 13:39:06
字體:
來源:轉載
供稿:網友

  活用 GregorianCalendar 類的 getTimeInMillis() 方法。
注重,取到的值是從1970年1月1日00:00:00開始算起所經過的微秒數。一秒是一千微秒。

下面是自己寫的一個例程及運行結果:

import java.util.GregorianCalendar;

class TestClender {

public static void main (String args[]) {

GregorianCalendar ca = new GregorianCalendar();
System.out.PRintln("ca: " + ca);
System.out.println("ca.time: " + ca.getTimeInMillis());

GregorianCalendar ca0 = new GregorianCalendar(2004-1900,11,31,23,59,59);
GregorianCalendar ca1 = new GregorianCalendar(2005-1900,00,01,00,00,02);
long sa = ca1.getTimeInMillis() - ca0.getTimeInMillis();
System.out.println("ca1-ca0: " + sa);

//2004.11.05 added
String old = "20041231235959";
int old_yyyy = Integer.parseInt(old.substring(0,4));
int old_mm = Integer.parseInt(old.substring(4,6));
int old_dd = Integer.parseInt(old.substring(6,8));
int old_hh = Integer.parseInt(old.substring(8,10));
int old_mi = Integer.parseInt(old.substring(10,12));
int old_ss = Integer.parseInt(old.substring(12,14));
String now = "20050101235959";
int now_yyyy = Integer.parseInt(now.substring(0,4));
int now_mm = Integer.parseInt(now.substring(4,6));
int now_dd = Integer.parseInt(now.substring(6,8));
int now_hh = Integer.parseInt(now.substring(8,10));
int now_mi = Integer.parseInt(now.substring(10,12));
int now_ss = Integer.parseInt(now.substring(12,14));
GregorianCalendar gcOld = new GregorianCalendar(
old_yyyy-1900,old_mm-1,old_dd,old_hh,old_mi,old_ss);
GregorianCalendar gcNow = new GregorianCalendar(
now_yyyy-1900,now_mm-1,now_dd,now_hh,now_mi,now_ss);
sa = gcNow.getTimeInMillis() - gcOld.getTimeInMillis();
System.out.println("now-old: " + sa);

}

}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高雄市| 密云县| 万山特区| 内乡县| 连州市| 花莲市| 于都县| 孝感市| 永春县| 宜川县| 成都市| 河南省| 千阳县| 天长市| 玛曲县| 长岭县| 钦州市| 泰宁县| 通海县| 兰西县| 龙山县| 南城县| 永寿县| 翼城县| 韶山市| 射洪县| 普定县| 清原| 通渭县| 乌拉特中旗| 乌鲁木齐县| 西华县| 靖江市| 安宁市| 聊城市| 津南区| 东至县| 乐东| 山西省| 扶绥县| 宝山区|