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; } }
标签:java,String,SimpleDateFormat,date,日期,dateStr,Date,格式 来源: https://www.cnblogs.com/Samuel-Leung/p/10373685.html