zoukankan      html  css  js  c++  java
  • excel -> easyexcel java时间转换问题

    https://blog.csdn.net/qq_20009015/article/details/85243033

    导入日期的有3种方式:
    1.excel文档日期列设置为文本类型,用LocalDateTimeConverter.class
    2.类中日期变量类型改为Date, 加上@DateTimeFormat
    3.excel日期字段是按一定规则生成的数字,自定义转换器将数字转为日期,参考https://blog.csdn.net/qq_20009015/article/details/85243033

    LocalDateTime:

    public class LocalDateTimeConverter implements Converter<LocalDateTime> {
        @Override
        public Class supportJavaTypeKey() {
            return LocalDateTime.class;
        }
    
        @Override
        public CellDataTypeEnum supportExcelTypeKey() {
            return CellDataTypeEnum.STRING;
        }
    
        @Override
        public LocalDateTime convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
            return LocalDateTime.parse(cellData.getStringValue(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        }
    
        @Override
        public CellData convertToExcelData(LocalDateTime value, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
            return new CellData<>(value.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        }
    }
    

    如下

        @ExcelProperty(value = "创建时间", converter = LocalDateTimeConverter.class)
        private LocalDateTime createTime;
    

    Date:

    package com.alibaba.excel.annotation.format;
    
    @java.lang.annotation.Target({java.lang.annotation.ElementType.FIELD})
    @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
    @java.lang.annotation.Inherited
    public @interface DateTimeFormat {
        java.lang.String value() default "";
    
        boolean use1904windowing() default false;
    }
    

    如下

        @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
        private Date createtime;
    
  • 相关阅读:
    ifdef有大用处
    osgEarth编译
    CyanogenMod 7.1 for Sony Ericsson X8 下载 CM7.1 for 索爱X8下载
    ArcGIS影像配准与空间配准
    ArcGIS Server的切图原理深入
    Arcgis server的rest服务url写法解读
    地图切片公式
    新随笔
    solr的java调用
    配置文件
  • 原文地址:https://www.cnblogs.com/ukzq/p/14182622.html
Copyright © 2011-2022 走看看