This article shares the specific code for the DateUtil tool time stamp type conversion for your reference. The specific content is as follows
package com.sinosoft.media.sms.util; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateUtil { //Current time//public static Date DATE_NOW=new Date(); /** * Get the complete timestamp, format: yyyyMMddHHmmssSSS (year, month, day, hour, minute, second, milliseconds) * @return Complete timestamp*/ public static String getFullTimeStamp(){ return new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) ; } /** * Get a simple timestamp, format: yyyyMMdd(year, month, day) * @return Simple timestamp*/ public static String getSimpleTimeStamp(){ return new SimpleDateFormat("yyyyMMdd").format(new Date()) ; } /** * Get a time stamp based on the specified format* @param pattern Specified format* @return Timestamp of the specified format*/ public static String getTimeStampByPattern(String pattern){ return new SimpleDateFormat(pattern).format(new Date()) ; } /** * Get the string formatted by the current date, format: yyyy-MM-dd(year-month-day) * @return The string formatted by the current date*/ public static String getTodayStr(){ return new SimpleDateFormat("yyyy-MM-dd").format(new Date()) ; } /** * Time stamp, format: yyyy-MM-dd HH:mm:ss(year-month-day-time: minutes: seconds) * @return Simple timestamp*/ public static String getDateTimeStamp(Date date){ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date) ; } public static Date getDateByString(String str){ SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date dateTime = null; try { dateTime = sim.parse(str); } catch (ParseException e) { e.printStackTrace(); } return dateTime; } }The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.