?? processtime.java
字號:
package com.shfe.mail;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: Shanghai futures information technologies, ltd .co.</p>
*
* @author JianJun Liu
* @version 1.0
*/
import java.util.*;
import java.text.*;
public class ProcessTime {
public static GregorianCalendar convertTime(String dateTime) {
SimpleDateFormat df0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
Date tradeTime = null;
try {
tradeTime = df0.parse(df1.format(new Date()) + " " + dateTime);
} catch (Exception e) {
}
GregorianCalendar tempDate = new GregorianCalendar();
tempDate.setTime(tradeTime);
return tempDate;
}
public static Date convertDate(String dateTime) {
SimpleDateFormat df0 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
Date tradeTime = null;
try {
tradeTime = df0.parse(df1.format(new Date()) + " " + dateTime);
} catch (Exception e) {
}
return tradeTime;
}
public static int[] computeHourMinute(String contractType) {
int[] hourMinute = new int[2];
if (contractType.equalsIgnoreCase("I") ||
contractType.equalsIgnoreCase("S")) {
GregorianCalendar stockOpenDate = getCaleDate(9, 30);
hourMinute[0] = stockOpenDate.get(Calendar.HOUR_OF_DAY); //=8
hourMinute[1] = stockOpenDate.get(Calendar.MINUTE);
} else {
GregorianCalendar optionOpenDate = getCaleDate(9, 15);
hourMinute[0] = optionOpenDate.get(Calendar.HOUR_OF_DAY); //=8
hourMinute[1] = optionOpenDate.get(Calendar.MINUTE);
}
return hourMinute;
}
public static GregorianCalendar getCaleDate(int hour, int minute) {
GregorianCalendar gcal = new GregorianCalendar();
GregorianCalendar caleDate = new GregorianCalendar(gcal.get(
Calendar.YEAR),
gcal.get(Calendar.MONTH), gcal.get(Calendar.DAY_OF_MONTH), hour,
minute);
return caleDate;
}
public static Date reverseTime(long tempLong) {
GregorianCalendar optionOpenDate = getCaleDate(9, 15);
GregorianCalendar optionBreakDate = getCaleDate(11, 30);
GregorianCalendar optionContinueDate = getCaleDate(13, 0);
GregorianCalendar optionCloseDate = getCaleDate(15, 15);
GregorianCalendar gcTempDate=new GregorianCalendar();
Date tempDate = null;
if (tempLong*1000 >= optionOpenDate.getTimeInMillis() &&
tempLong*1000 <= optionBreakDate.getTimeInMillis()) {
gcTempDate.setTimeInMillis(tempLong*1000);
tempDate = gcTempDate.getTime();
//System.out.println("tempLong1="+tempLong);
} else if (tempLong*1000 >= optionContinueDate.getTimeInMillis() &&
tempLong*1000 <= optionCloseDate.getTimeInMillis()) {
gcTempDate.setTimeInMillis(tempLong*1000+15*6*60*1000);
tempDate = gcTempDate.getTime();
}
return tempDate;
//return Integer.parseInt((new Long(tempLong)).toString());
}
public static long judgeTime(GregorianCalendar tempDate) {
GregorianCalendar optionOpenDate = getCaleDate(9, 15);
GregorianCalendar optionBreakDate = getCaleDate(11, 30);
GregorianCalendar optionContinueDate = getCaleDate(13, 0);
GregorianCalendar optionCloseDate = getCaleDate(15, 15);
long tempLong = 0;
if (tempDate.getTimeInMillis() >= optionOpenDate.getTimeInMillis() &&
tempDate.getTimeInMillis() <= optionBreakDate.getTimeInMillis()) {
tempLong = (tempDate.getTimeInMillis() - optionOpenDate.getTimeInMillis()) / 1000;
} else if (tempDate.getTimeInMillis() >= optionContinueDate.getTimeInMillis() &&
tempDate.getTimeInMillis() <= optionCloseDate.getTimeInMillis()) {
tempLong = (tempDate.getTimeInMillis() - optionOpenDate.getTimeInMillis()) / 1000 - 15 * 6 * 60;
}
return tempLong;
//return Integer.parseInt((new Long(tempLong)).toString());
}
public static long judgeTime(String contractType,
GregorianCalendar tempDate) {
GregorianCalendar stockOpenDate = getCaleDate(9, 30);
GregorianCalendar stockBreakDate = getCaleDate(11, 30);
GregorianCalendar stockContinueDate = getCaleDate(13, 0);
GregorianCalendar stockCloseDate = getCaleDate(15, 0);
GregorianCalendar optionOpenDate = getCaleDate(9, 15);
GregorianCalendar optionBreakDate = getCaleDate(11, 30);
GregorianCalendar optionContinueDate = getCaleDate(13, 0);
GregorianCalendar optionCloseDate = getCaleDate(15, 15);
long tempLong = 0;
//I:index F:future S:spot O:option
if (contractType.equalsIgnoreCase("I") ||
contractType.equalsIgnoreCase("S")) {
if (tempDate.getTimeInMillis() >= stockOpenDate.getTimeInMillis() &&
tempDate.getTimeInMillis() <= stockBreakDate.getTimeInMillis()) {
tempLong = (tempDate.getTimeInMillis() -
stockOpenDate.getTimeInMillis()) / 1000;
} else if (tempDate.getTimeInMillis() >=
stockContinueDate.getTimeInMillis() &&
tempDate.getTimeInMillis() <=
stockCloseDate.getTimeInMillis()) {
tempLong = (tempDate.getTimeInMillis() -
stockOpenDate.getTimeInMillis()) / 1000 -
15 * 6 * 60;
}
} else {
if (tempDate.getTimeInMillis() >= optionOpenDate.getTimeInMillis() &&
tempDate.getTimeInMillis() <= optionBreakDate.getTimeInMillis()) {
tempLong = (tempDate.getTimeInMillis() -
optionOpenDate.getTimeInMillis()) / 1000;
//System.out.println("tempLong1="+tempLong);
} else if (tempDate.getTimeInMillis() >=
optionContinueDate.getTimeInMillis() &&
tempDate.getTimeInMillis() <=
optionCloseDate.getTimeInMillis()) {
tempLong = (tempDate.getTimeInMillis() -
optionOpenDate.getTimeInMillis()) / 1000 -
15 * 6 * 60;
}
}
return tempLong;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -