?? time.java
字號:
/*
* Created on 2004-9-17
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package oa.sys;
import java.util.*;
import java.text.*;
/**
****************************************************
*類名稱: Time<br>
*類功能: 時間操作<br>
*創建: 白偉明 2004年9月23日<br>
****************************************************
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class Time {
private Date time,timem;
private String strtime;
private SimpleDateFormat format;
private SimpleDateFormat format1;
/**
* 初始化
*/
public Time() {
time=new Date();
strtime="";
format=null;
}
/***************************************************
*函數名稱: getYear()<br>
*函數功能: 取得年份<br>
*返回值: int<br>
*參數說明: 無<br>
*創建: 白偉明
* 2004年9月18日<br>
*最后修改: 無
****************************************************/
public int getYear(){
format=new SimpleDateFormat("yyyy",Locale.getDefault());
strtime=format.format(time);
return Integer.parseInt(strtime);
}
/***************************************************
*函數名稱: getMonth()<br>
*函數功能: 取得月份<br>
*返回值: int<br>
*參數說明: 無<br>
*創建: 白偉明
* 2004年9月18日<br>
*最后修改: 無
****************************************************/
public int getMonth(){
format=new SimpleDateFormat("MM",Locale.getDefault());
strtime=format.format(time);
return Integer.parseInt(strtime);
}
/***************************************************
*函數名稱: getSunr()<br>
*函數功能: 取得日份<br>
*返回值: int<br>
*參數說明: 無<br>
*創建: 白偉明
* 2004年9月18日<br>
*最后修改: 無
****************************************************/
public int getSun(){
format=new SimpleDateFormat("dd",Locale.getDefault());
strtime=format.format(time);
return Integer.parseInt(strtime);
}
/***************************************************
*函數名稱: getWeek()<br>
*函數功能: 取得星期<br>
*返回值: int<br>
*參數說明: 無<br>
*創建: 白偉明
* 2004年9月18日<br>
*最后修改: 無
****************************************************
public int getWeek(){
return time.getDay();
}
/***************************************************
*函數名稱: getHour()<br>
*函數功能: 取得小時<br>
*返回值: int<br>
*參數說明: 無<br>
*創建: 白偉明
* 2004年9月18日<br>
*最后修改: 無
****************************************************/
public int getHour(){
format=new SimpleDateFormat("HH",Locale.getDefault());
strtime=format.format(time);
return Integer.parseInt(strtime);
}
/***************************************************
*函數名稱: getMinu()<br>
*函數功能: 取得分鐘<br>
*返回值: int<br>
*參數說明: 無<br>
*創建: 白偉明<br>
* 2004年9月18日<br>
*最后修改: 無
****************************************************/
public int getMinu(){
format=new SimpleDateFormat("mm",Locale.getDefault());
strtime=format.format(time);
return Integer.parseInt(strtime);
}
/***************************************************
*函數名稱: getSecond()<br>
*函數功能: 取得秒數<br>
*返回值: String<br>
*參數說明: 無<br>
*創建: 白偉明
* 2004年9月18日<br>
*最后修改: 無
****************************************************/
public int getSecond(){
format=new SimpleDateFormat("ss",Locale.getDefault());
strtime=format.format(time);
return Integer.parseInt(strtime);
}
/***************************************************
*函數名稱: getYMD()<br>
*函數功能: 取得年-月-日<br>
*返回值: String<br>
*參數說明: 無<br>
*創建: 白偉明
* 2004年9月18日<br>
*最后修改: 無
****************************************************/
public String getYMD(){
format=new SimpleDateFormat("yyyy-MM-dd",Locale.getDefault());
strtime=format.format(time);
return strtime;
}
/***************************************************
*函數名稱: getHMS()<br>
*函數功能: 取得時:分:秒<br>
*返回值: String<br>
*參數說明: 無<br>
*創建: 白偉明
* 2004年9月18日<br>
*最后修改: 無
****************************************************/
public String getHMS(){
format=new SimpleDateFormat("HH:mm:ss",Locale.getDefault());
strtime=format.format(time);
return strtime;
}
/***************************************************
*函數名稱: getYMDHMS()<br>
*函數功能: 取得年-月-日 時:分:秒<br>
*返回值: String<br>
*參數說明: 無<br>
*創建: 白偉明
* 2004年9月18日<br>
*最后修改: 無
****************************************************/
public String getYMDHMS(){
format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.getDefault());
strtime=format.format(time);
return strtime;
}
/***************************************************
*函數名稱: getMinH<br>
*函數功能: 獲小時間差,輸入的時間減現在的時間<br>
*返回值: int<br>
*參數說明: 無<br>
*創建: 白偉明
* 2004年10月4日<br>
*最后修改: 無
****************************************************/
public int getMinH(String in){
format = new SimpleDateFormat ("HH:mm:ss", Locale.getDefault());
format1=new SimpleDateFormat("HH",Locale.getDefault());
try {
timem=format.parse(in);
strtime=format1.format(timem);
System.err.print(strtime);
} catch (ParseException e) {
e.printStackTrace();
}
return Integer.parseInt(strtime)-this.getHour();
}
/***************************************************
*函數名稱: getMinM<br>
*函數功能: 獲分鐘差,輸入的時間減現在的時間<br>
*返回值: int<br>
*參數說明: 無<br>
*創建: 白偉明
* 2004年10月4日<br>
*最后修改: 無
****************************************************/
public int getMinM(String in){
format = new SimpleDateFormat ("HH:mm:ss", Locale.getDefault());
format1=new SimpleDateFormat("mm",Locale.getDefault());
try {
timem=format.parse(in);
strtime=format1.format(timem);
} catch (ParseException e) {
e.printStackTrace();
}
return Integer.parseInt(strtime)-this.getMinu();
}
/***************************************************
*函數名稱: getMinS<br>
*函數功能: 獲秒差,輸入的時間減現在的時間<br>
*返回值: int<br>
*參數說明: 無<br>
*創建: 白偉明
* 2004年10月4日<br>
*最后修改: 無
****************************************************/
public int getMinS(String in){
format = new SimpleDateFormat ("HH:mm:ss", Locale.getDefault());
format1=new SimpleDateFormat("ss",Locale.getDefault());
try {
timem=format.parse(in);
strtime=format1.format(timem);
} catch (ParseException e) {
e.printStackTrace();
}
return Integer.parseInt(strtime)-this.getSecond();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -