今天项目中遇到一个格式问题,收到的timestamp格式是2019-08-19-16:03:21 , 但是入es时,当类型为date的时候,这种格式直接报错,因为索引建的格式是yyyy-MM-dd HH:mm:ss,即中间多了一个横杠。

 

解决思路,先把时间转化成Date类型,然后再把Date转成字符串的类型。

 

String --> Date 

/**
     *    @Title:         字符串转日期
     *    @MethodName:    parse 
     *    @Description:    
     *    @param             @param strDate
     *    @param             @param pattern
     *    @param             @return
     *    @return         Date
     *    @throws
     */
    public static Date parse(String strDate, String pattern) {
        SimpleDateFormat df = new SimpleDateFormat(pattern);
        try {
            return df.parse(strDate);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
View Code

相关文章:

  • 2021-10-30
  • 2022-12-23
  • 2021-09-16
  • 2021-12-22
  • 2021-08-30
  • 2021-11-12
  • 2021-12-29
猜你喜欢
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2021-12-15
  • 2021-11-23
  • 2022-12-23
相关资源
相似解决方案