package com.weixin.jahwajob.utils;
import org.jetbrains.annotations.NotNull;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @className: ExcelDoubleToDate
* @description: ExcelDoubleToDate
* @author: suntiancheng
* @create: 2023-05-02 17:19
**/
public class ExcelDoubleToDate {
//解析Excel日期格式
public static Date ExcToDate(@NotNull String strDate) {
if(strDate.length() == 5){// 例:把解析出来的44023转换为2020-07-11
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date tDate = DoubleToDate(Double.parseDouble(strDate));
return tDate;
//return sdf.format(tDate);
}catch (Exception e){
e.printStackTrace();
return FormatUtils.formatDateAppoint(strDate, "yyyy-MM-dd");
// return strDate;
}
}
strDate = strDate.replaceAll("\\\\", "-");//stc add 把字符串中的反斜杠(\)替换成-
strDate = strDate.replaceAll("/", "-");//stc add 把字符串中的正斜杠(/)替换成-
return FormatUtils.formatDateAppoint(strDate, "yyyy-MM-dd");
// return strDate;
}
//解析Excel日期格式
public static Date DoubleToDate(Double dVal) {
Date tDate = new Date();
long localOffset = tDate.getTimezoneOffset() * 60000; //系统时区偏移 1900/1/1 到 1970/1/1 的 25569 天
tDate.setTime((long) ((dVal - 25569) * 24 * 3600 * 1000 + localOffset));
return tDate;
}
}
java解析Excel日期格式转换问题-完整版
于 2023-05-06 14:54:08 首次发布
3098

被折叠的 条评论
为什么被折叠?



