package com.fgkj.fbo;
|
|
import java.util.Date;
|
import java.util.GregorianCalendar;
|
|
public class IdcTestTime {
|
public int year;
|
public int month;
|
public int dayofweek;
|
public int day;
|
public int hour;
|
public int minute;
|
public int second;
|
public int millsecond;
|
|
public long getTimeInSecond()
|
{
|
GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
|
gc.set(GregorianCalendar.YEAR, year);
|
gc.set(GregorianCalendar.MONTH, month-1);
|
gc.set(GregorianCalendar.DATE, day);
|
gc.set(GregorianCalendar.HOUR_OF_DAY, hour);
|
gc.set(GregorianCalendar.MINUTE, minute);
|
gc.set(GregorianCalendar.SECOND, second);
|
|
return (gc.getTimeInMillis()/1000);
|
}
|
|
public static Date getDateFromStr(String str_time)
|
{
|
GregorianCalendar gc = (GregorianCalendar) GregorianCalendar.getInstance();
|
int year = 1, month = 1, day = 1, hour = 0, minute = 0, second = 0;
|
|
String str = str_time;
|
|
if(str.indexOf("-") >= 0) {
|
year = Integer.parseInt(str.substring(0, str.indexOf("-")).trim());
|
str = str.substring(str.indexOf("-")+1, str.length());
|
month = Integer.parseInt(str.substring(0, str.indexOf("-")).trim());
|
str = str.substring(str.indexOf("-")+1, str.length());
|
} else if(str.indexOf("/") >= 0) {
|
year = Integer.parseInt(str.substring(0, str.indexOf("/")).trim());
|
str = str.substring(str.indexOf("/")+1, str.length());
|
month = Integer.parseInt(str.substring(0, str.indexOf("/")).trim());
|
str = str.substring(str.indexOf("/")+1, str.length());
|
}
|
|
if(str.indexOf(" ") >= 0) {
|
day = Integer.parseInt(str.substring(0, str.indexOf(" ")).trim());
|
str = str.substring(str.indexOf(" ")+1, str.length()).trim();
|
} else {
|
day = Integer.parseInt(str.trim());
|
str = str.trim();
|
}
|
|
if(year < day) {
|
int tmp = year;
|
year = day;
|
day = tmp;
|
}
|
|
if(str.indexOf(" ") >= 0) {
|
str = str.substring(str.indexOf(" ")+1, str.length());
|
}
|
if(str.indexOf(":") >= 0) {
|
hour = Integer.parseInt(str.substring(0, str.indexOf(":")).trim());
|
if(str_time.contains("����")) {
|
if(hour < 12) {
|
hour += 12;
|
}
|
}
|
str = str.substring(str.indexOf(":")+1, str.length());
|
|
minute = Integer.parseInt(str.substring(0, str.indexOf(":")).trim());
|
str = str.substring(str.indexOf(":")+1, str.length());
|
|
second = Integer.parseInt(str.trim());
|
}
|
|
gc.set(GregorianCalendar.YEAR, year-2000);
|
gc.set(GregorianCalendar.MONTH, month);
|
gc.set(GregorianCalendar.DATE, day);
|
gc.set(GregorianCalendar.HOUR_OF_DAY, hour);
|
gc.set(GregorianCalendar.MINUTE, minute);
|
gc.set(GregorianCalendar.SECOND, second);
|
|
return gc.getTime();
|
}
|
|
public static FboTestTime getFboTestTime(IdcTestTime t_end, IdcTestTime t_begin)
|
{
|
FboTestTime fbo_time = new FboTestTime();
|
long seconds = t_end.getTimeInSecond() - t_begin.getTimeInSecond();
|
fbo_time.hour = (int) (seconds / 3600);
|
fbo_time.minute = (int) ((seconds % 3600) / 60);
|
fbo_time.second = (int) (seconds % 60);
|
|
return fbo_time;
|
}
|
}
|