/**
* @ 业务描述:
* @ Package_name:com.ratel.easypoi
* @ Project_name:easypoi
* @ Author:ratelfu@qq.com
* @ Create_time:2019-01-11 10:37
* @ Copyright (c) ratelfu 版权所有
*/
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtils {
public final static String Format_DateTime = "yyyy-MM-dd HH:mm:ss";
public final static String Format_Date = "yyyy-MM-dd";
public final static String Format_Time = "HH:mm:ss";
public final static String Hours_Minute = "HH:mm";
public static Long getLongByDateString(String dateString) {
return Long.valueOf(dateString);
}
/**
* @param dateString "1545276566000"
* @return 2018-12-20 11:29:26
*/
public static String getDateTimeFormatByDateString(String dateString) {
Date date = new Date(Long.valueOf(dateString));
return new SimpleDateFormat(Format_DateTime).format(date);
}
/**
* @param dateString "1545276566000"
* @return 11:29:27
*/
public static String getTimeFormatByDateString(String dateString) {
Date date = new Date(Long.valueOf(dateString));
return new SimpleDateFormat(Format_Time).format(date);
}
/**
* @param dateLong 1545276566000L
* @return 2018-12-20
*/
public static String getDateFormatByLong(Long dateLong) {
Date date = new Date(dateLong);
return new SimpleDateFormat(Format_Date).format(date);
}
/**
* @param dateLong 1545276566000L
* @return 11:29
*/
public static String getHoursMinuteFormatByDateString(Long dateLong) {
Date date = new Date(dateLong);
return new SimpleDateFormat(Hours_Minute).format(date);
}
/**
* @param dateString
* @param timeString
* @return 1544630399
*/
public static Long getLongByDateString(String dateString, String timeString) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Long endDate = null;
try {
endDate = formatter.parse(dateString + " " + timeString).getTime() / 1000;
} catch (ParseException e) {
e.printStackTrace();
}
return endDate;
}
}
/**
*
* @param date Fri Jan 11 15:32:32 CST 2019
* @return 2019-01-11
*/
public static String getStringByDate(Date date){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(date);
return dateString;
}
/**
* @param dateString 2018-12-20 / 2018-12-20 00:00:00
* @return Thu Dec 20 00:00:00 CST 2018
*/
public static Date getDateByString(String dateString ){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date date=new Date();
try {
date = formatter.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
时间转换
最新推荐文章于 2022-01-21 11:10:56 发布