工具类(一)-日期格式化工具类
package com. wang. mygateway. gateway. basecore. utils ;
import org. apache. dubbo. common. utils. StringUtils ;
import javax. xml. crypto. Data ;
import java. text. ParseException ;
import java. text. SimpleDateFormat ;
import java. util. Date ;
public class DateUtil {
private static final String format = "yyyy-MM-dd HH-mm-ss" ;
private DateUtil ( ) { }
public static String format ( Date time) {
return new SimpleDateFormat ( format) . format ( time) ;
}
public String format ( Date time, String format) {
if ( StringUtils . isBlank ( format) ) {
return format ( time) ;
} else {
return new SimpleDateFormat ( format) . format ( time) ;
}
}
public static String format ( Long time) {
return new SimpleDateFormat ( format) . format ( new Date ( time) ) ;
}
public static String format ( Long time, String format) {
if ( StringUtils . isBlank ( format) ) {
return format ( time) ;
} else {
return new SimpleDateFormat ( format) . format ( new Date ( time) ) ;
}
}
public static Date parse ( String time) {
try {
return new SimpleDateFormat ( format) . parse ( time) ;
} catch ( ParseException e) {
e. printStackTrace ( ) ;
return null ;
}
}
public static Date parse ( String time, String format) {
if ( StringUtils . isBlank ( format) ) {
return parse ( time) ;
} else {
try {
return new SimpleDateFormat ( format) . parse ( time) ;
} catch ( ParseException e) {
e. printStackTrace ( ) ;
return null ;
}
}
}
}