程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> 補充兩個有用的關於時間的函數

補充兩個有用的關於時間的函數

編輯:關於JAVA

/*

Time Functions.

[email protected]

*/

import Java.lang.*;

import Java.util.*;

import Java.text.ParsePosition;

import Java.text.SimpleDateFormat;

public class formatDateTime{

static String TimeFormat1="yyyy.MM.dd HH:mm:ss";

public formatDateTime(){

}

/*

Function name: lTimeCompare

Description: Compare two times

Input: String CompTime1,String CompTime2 (Format: yyyy.MM.dd HH:mm:ss)

Output: time diffrent by seconds

*/

public long lTimeCompare(String CompTime1,String CompTime2){

long iReturn=-1;

SimpleDateFormat sdf = new SimpleDateFormat(TimeFormat1);

Date DateTime1=sdf.parse(CompTime1,new ParsePosition(0));

Date DateTime2=sdf.parse(CompTime2,new ParsePosition(0));

iReturn=DateTime2.getTime()/1000L-DateTime1.getTime()/1000L;

return iReturn;

}

/*

Function name: lTimeCompareNow

Description: Compare one time with now

Input: String CompTime1(Format: yyyy.MM.dd HH:mm:ss)

Output: time diffrent by seconds

*/

public long lTimeCompareNow(String CompTime1){

long iReturn=-1;

SimpleDateFormat sdf = new SimpleDateFormat(TimeFormat1);

Date DateTime1=sdf.parse(CompTime1,new ParsePosition(0));

iReturn=Java.lang.System.currentTimeMillis()/1000L-DateTime1.getTime()/1000L;

return iReturn;

}

}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved