java常用方法3

/**
*@param   2005-11-03 09:23:00.0
*@return  2005-11-03
* @throws ParseException
* */
public static Date getFormatDateNoTime(Date date) {
String tempStr = Util.dateToString(date, Constants.DATETIMEFORMAT);
String tempDate = tempStr.substring(0, 10);
Date tempDateReturn = null;
tempDateReturn = Util.stringToDate(tempDate, Constants.DATEFORMAT);
return tempDateReturn;
}

public static Date addDay2Date(int dayAmount, Date date) {
Date newDate = null;
if (date != null) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, dayAmount);
newDate = calendar.getTime();
}
return newDate;
}

public static boolean isInTheDay(Date stDate, Date EndDate) {
boolean isIn = true;
Calendar startTime = Calendar.getInstance(); //开始时间
Calendar c = java.util.Calendar.getInstance();
c.setTime(stDate);
startTime.set(
c.get(Calendar.YEAR),
c.get(Calendar.MONTH),
c.get(Calendar.DAY_OF_MONTH),
0,
0,
0);

Calendar endTime = Calendar.getInstance(); //结束时间
c = java.util.Calendar.getInstance();
c.setTime(EndDate);
endTime.set(
c.get(Calendar.YEAR),
c.get(Calendar.MONTH),
c.get(Calendar.DAY_OF_MONTH) - 1,
23,
59,
59);

Calendar nowTime = Calendar.getInstance(); //当前时间
if (nowTime.getTime().getTime() <= endTime.getTime().getTime()
&& nowTime.getTime().getTime() >= startTime.getTime().getTime()) {
isIn = true;
} else {
isIn = false;
}

return isIn;
}
/**
* @param xmlfilepath XML文件实际地址
* @return     XML文件内容的字符串
* */
public static String getXMLString(String xmlfilepath) {
File file = new File(xmlfilepath);
if (!file.exists() || file.length() <= 0) {
return null;
} else {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
long fileLength = file.length();
byte[] fileBytes = new byte[(int) fileLength];
fis.read(fileBytes);
String fileData = new String(fileBytes);
return fileData;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
try {
if (fis != null) {
fis.close();
fis = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

你可能感兴趣的:(java,C++,c,xml,C#)