`
wangyijiangshui
  • 浏览: 83328 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类
收藏列表
标题 标签 来源
小时格式化
/**
 * 使用指定的格式,格式化指定的小数,默认格式:#0.00
 * 
 * @param formatStr
 * @return
 */
public double formatDouble(double num, String formatStr) {
	double result = 0;
	if(null == formatStr || "".equals(formatStr))formatStr = "#0.00";
	NumberFormat format = null;
		
	try {
		format = new DecimalFormat(formatStr);
		result = Double.parseDouble(format.format(num));
	} catch (NumberFormatException e) {
		e.printStackTrace();
	} finally {
		format = null;
	}
	return result;
}
Jxl操作Excel jxl
/**
 * 处理jxl中日期cell
 * 
 * @param cell	
 * @param pattern	格式化日期的模式
 * @return
 */
public String formatDataCell(Cell cell, String pattern) {
  if(null == pattern || "".equals(pattern))pattern = "yyyy-MM-dd HH:mm:ss";
  String dateStr = null;
  SimpleDateFormat sdf=new SimpleDateFormat(pattern);
  if (cell.getType() == CellType.DATE) {
	dateStr = sdf.format(((DateCell)cell).getDate());
  } else {
	dateStr = cell.getContents();
  }
  sdf = null;
  return dateStr;
}


/**
 * 处理jxl中日期cell
 * 
 * @param cell	
 * @param pattern	格式化日期的模式
 * @return
 */
public Date formatDataCell(Cell cell, String pattern) {
  if(null == pattern || "".equals(pattern))pattern = "yyyy-MM-dd";
  Date date = null;
  SimpleDateFormat sdf=new SimpleDateFormat(pattern);
  if (cell.getType() == CellType.DATE) {
	date = ((DateCell)cell).getDate();
  } else {
	String temp = cell.getContents();
	if(null != temp && !"".equals(temp.trim())); {
	  try {
		date = sdf.parse(temp.trim());
	  } catch (ParseException e) {
		e.printStackTrace();
	  }
        }
  }
  sdf = null;
  return date;
}
Global site tag (gtag.js) - Google Analytics