提交 abd27dd9 作者: zgz

日期格式化

上级 08695adf
...@@ -190,7 +190,7 @@ public class InformationServiceImpl implements InformationService { ...@@ -190,7 +190,7 @@ public class InformationServiceImpl implements InformationService {
for (SpecialInformation specialInformation : records) { for (SpecialInformation specialInformation : records) {
DisplayInfo info = new DisplayInfo(); DisplayInfo info = new DisplayInfo();
BeanUtils.copyProperties(specialInformation, info); BeanUtils.copyProperties(specialInformation, info);
info.setPublishDate(EsDateUtil.esFieldDateMapping(info.getPublishDate())); info.setPublishDate(EsDateUtil.esFieldDateYmd(info.getPublishDate()));
//标签处理 //标签处理
List<LabelModelVo> modelVoList = modelMap.get(info.getSubjectId()); List<LabelModelVo> modelVoList = modelMap.get(info.getSubjectId());
formatLabel(modelVoList, info); formatLabel(modelVoList, info);
...@@ -228,7 +228,7 @@ public class InformationServiceImpl implements InformationService { ...@@ -228,7 +228,7 @@ public class InformationServiceImpl implements InformationService {
num++; num++;
DisplayInfo info = new DisplayInfo(); DisplayInfo info = new DisplayInfo();
BeanUtils.copyProperties(specialInformation, info); BeanUtils.copyProperties(specialInformation, info);
info.setPublishDate(EsDateUtil.esFieldDateMapping(info.getPublishDate())); info.setPublishDate(EsDateUtil.esFieldDateYmd(info.getPublishDate()));
//标签处理 //标签处理
List<LabelModelVo> modelVoList = modelMap.get(info.getSubjectId()); List<LabelModelVo> modelVoList = modelMap.get(info.getSubjectId());
formatLabel(modelVoList, info); formatLabel(modelVoList, info);
......
package com.zzsn.event.util; package com.zzsn.event.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/** /**
* Es对日期类型处理 * Es对日期类型处理
* @author kongliufeng * @author kongliufeng
...@@ -38,4 +42,29 @@ public class EsDateUtil { ...@@ -38,4 +42,29 @@ public class EsDateUtil {
} }
return null; return null;
} }
/**
* yyyy-MM-dd HH:mm:ss ->yyyy-MM-dd
* @param data
* @return
*/
public static String esFieldDateYmd(String data) {
// 创建一个SimpleDateFormat对象,用于解析和格式化日期
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy年M月d日");
try {
if (data == null){
return data;
}
// 解析输入的日期字符串
Date date = inputFormat.parse(data);
// 格式化日期为指定的输出格式
String formattedDate = outputFormat.format(date);
return formattedDate;
} catch (ParseException e) {
// 输入的日期格式不正确时,打印错误信息
System.out.println("日期格式错误"+e);
}
return null;
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论