`
vencent888
  • 浏览: 139633 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

java常用方法3

    博客分类:
  • java
阅读更多
/**
*@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();
}
}
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics