content: package com.jeespring.modules.iim.utils;
  
  
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  
  /**
   * 日期及时间处理函数
   * 
   * @author liugf
   */
  public class DateUtil {
  
  	private static final String DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss";
  
  	/**
  	 * 字符串时间转LONG
  	 * @param sdate
  	 * @return
  	 */
  	public static long string2long(String sdate){
  		if(sdate.length() < 11){
  			sdate = sdate + " 00:00:00";
  		}
  		SimpleDateFormat sdf= new SimpleDateFormat(DEFAULT_PATTERN);
  		Date dt2 = null;
  		try {
  			dt2 = sdf.parse(sdate);
  		} catch (ParseException e) {
  			e.printStackTrace();
  		}
  		//继续转换得到秒数的long型
  		long lTime = dt2.getTime() / 1000;
  		return lTime;
  	}
  	
  	/**
  	 * LONG时间转字符串
  	 * @param ldate
  	 * @return
  	 */
  	public static String long2string(long ldate){
  		SimpleDateFormat sdf= new SimpleDateFormat(DEFAULT_PATTERN);
  		//前面的ldate是秒数，先乘1000得到毫秒数，再转为java.util.Date类型
  		Date dt = new Date(ldate * 1000);
  		String sDateTime = sdf.format(dt);  //得到精确到秒的表示
  		if(sDateTime.endsWith("00:00:00")){
  			sDateTime = sDateTime.substring(0,10);
  		}
  		return sDateTime;
  	}
  }
  