com.vonchange.headb.utils.time.HDateUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of headb Show documentation
Show all versions of headb Show documentation
ORM which The highest development efficiency and Efficiency is the fastest
The newest version!
package com.vonchange.headb.utils.time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
* 日期组件
* @author [email protected]
* @date 2015-6-13 下午7:44:10
*/
public class HDateUtils extends com.vonchange.headb.utils.time.third.ADateUtils {
private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
private HDateUtils() {
}
public static TimeZone getGMTTimeZone() {
return GMT;
}
public static String dateString(Date date){
return format("yyyyMMdd", date);
}
public static String dateString(){
return dateString(new Date());
}
private static TimeZone getDefaultTimeZone() {
return null;
}
public static Date parse(String dateText) {
try {
return HDateUtils.parseE(dateText);
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
public static Date parseE(String dateText) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat();
TimeZone timeZone = getDefaultTimeZone();
if (timeZone != null) {
sdf.setTimeZone(timeZone);
}
return sdf.parse(dateText);
}
public static Date parse(String format, String dateText) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat(format);
TimeZone timeZone = getDefaultTimeZone();
if (timeZone != null) {
sdf.setTimeZone(timeZone);
}
return sdf.parse(dateText);
}
public static String format(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat();
TimeZone timeZone = getDefaultTimeZone();
if (timeZone != null) {
sdf.setTimeZone(timeZone);
}
return sdf.format(date);
}
public static String format(String format, Date date) {
SimpleDateFormat sdf = new SimpleDateFormat(format);
TimeZone timeZone = getDefaultTimeZone();
if (timeZone != null) {
sdf.setTimeZone(timeZone);
}
return sdf.format(date);
}
public static void main(String[] args) {
System.out.println(HDateUtils.parse("2012-12-11 12:11:11"));
}
}