/**
* 将Long类型的时间戳转换为日期格式Apr-02-2020 18:00:00
* @param date
* @return
*/
public static String dateFormatMMM(Date date){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM-dd-yyyy HH:mm:ss", Locale.ENGLISH);
String dateFormat = simpleDateFormat.format(date);
return dateFormat;
}
/**
* 时间戳转换成日期格式字符串 /Date(1594348830000+0000)/
* @param seconds 精确到秒的字符串
* @param dateFormat
* @return
*/
public static String timeStamp2Date(String seconds, String... dateFormat) {
String format = FORMAT_DATETIME_Y4MDHMS;
if(seconds == null || seconds.isEmpty() || seconds.equals("null")){
return "";
} else {
if (seconds.contains("/Date")) {
seconds = seconds.replace("/Date(", "").replace("+0000)/", "");
}
}
if(dateFormat != null && dateFormat.length > 0){
format = dateFormat[0];
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(new Date(Long.valueOf(seconds)));
}
/**
* 时间戳转换成日期格式字符串 /Date(1594348830000)/
* @param seconds 精确到秒的字符串
* @param dateFormat
* @return
*/
public static String timeStamp2DateT(String seconds, String... dateFormat) {
String format = FORMAT_DATETIME_Y4MDHMS;
if(seconds == null || seconds.isEmpty() || seconds.equals("null")){
return "";
} else {
if (seconds.contains("/Date")) {
seconds = seconds.replace("/Date(", "").replace(")/", "");
}
}
if(dateFormat != null && dateFormat.length > 0){
format = dateFormat[0];
}
SimpleDateFormat sdf = new SimpleDateFormat(format);
return sdf.format(new Date(Long.valueOf(seconds)));
}
/**
* 时间戳转换成带时区日期格式字符串(减去8小时) /Date(1594348830000)/->2014-07-1T08:00:00
* @param timeStampStr
* @return
*/
public static String timeStamp2TimeZoneDate(String timeStampStr){
String startDateTimeStamp = DateUtil.timeStamp2DateT(timeStampStr,"yyyy-MM-dd HH:mm:ss");
Date date = D.datetimeString2Date(startDateTimeStamp);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.HOUR_OF_DAY,-8);// before 8 hour
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
String sim = sdf.format(cal.getTime());
return sim;
}
日期格式相互转换
最新推荐文章于 2022-03-15 09:35:45 发布