项目中用到的时间的公共类,整理出来,呵呵!!
public class DateUtil {
// 定义常量
public static final String yyyyMMdd = "yyyy-MM-dd"; // 精确到天
public static final String yyyyMMddmm = "yyyy-MM-dd hh:mm:00"; // 精确到分(秒为补零)
public static final String HHmmss = "HH:mm:ss";
public static final String yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss"; // 精确到秒
public static final String yyMMddHHmmss = "yy-MM-dd HH:mm:ss";
/**
* <pre>
* 根据plDateLine参数和pstrStyle参数,格式返回日期.
* </pre>
*
* @param plDateLine long
* @param pstrStyle String
* @return mstrDate
* @author aa00aa00 2011-5-19
*/
public static String parseToDate(long plDateLine, String pstrStyle) {
SimpleDateFormat objFormatter = new SimpleDateFormat();
objFormatter.applyPattern(pstrStyle);
Date objDate = null;
String mstrDate = null;
try {
objDate = new Date(plDateLine);
mstrDate = objFormatter.format(objDate);
} catch (Exception e) {
return "";
}
return mstrDate;
}
2.调用方式举例:
// 评论时间戳
objCommentDTO.setMstrCreatedtime(DateUtil.parseToDate(
pobComment.getMnCreatedtime() * 1000l, DateUtil.yyyyMMddmm));