java开发常用的日期格式转换工具类

package com.ydtf.ipcc.sms.util;
 
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
     
    /**
     * 将Date转换成String
  
     */
    public String date2String(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateStr = sdf.format(date);
        return dateStr;
    }
     
    /**
     * 将Timestamp转换成String
     * 用于数据库中字段类型为datetime
     
     */
    public String time2String(Timestamp timestamp) {
        Date date = new Date(timestamp.getTime());
        String dateStr = date2String(date);
        return dateStr;
    }
 
}

 

转载于:https://www.cnblogs.com/Samuel-Leung/p/10373685.html

你可能感兴趣的:(java,数据库)