首页 > 其他 > 详细

时间格式化工具类

时间:2014-11-28 22:41:37      阅读:368      评论:0      收藏:0      [点我收藏+]

package com.sec.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTimeUtil {
/**
* string类型改为Date(时、分、秒)
*
*/
public static Date convertDate(String dateStr){
if(StringUtil.isNullOrEmpty(dateStr)){
return null;
}
Date d = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
d = sdf.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
return d;
}

/**
* 将Date改为date类型
* @param data
* @return
*/
public static String convertDate(Date date) {
if(null==date){
return "";
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}

/**
*
* @param date
* @return
*/
public static String convertDateNoTime(Date date) {
if(null==date){
return "";
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(date);
}
}

时间格式化工具类

原文:http://www.cnblogs.com/bsyx/p/4129436.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!