作者 王勇

封装时间转换

package com.sunyo.wlpt.message.bus.service.utils;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
... ... @@ -86,4 +87,18 @@ public class DateUtils {
calendar.add(Calendar.DATE, days);
return calendar.getTime();
}
/**
* 将字符串时间转换成 java.util.Date 类型
*
* @param strDate 格式为 yyyyMMddHHmmss 的时间字符串
* @return java.util.Date
*/
public static Date strToDateLong(String strDate)
{
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
ParsePosition pos = new ParsePosition(0);
Date strtodate = formatter.parse(strDate, pos);
return strtodate;
}
}
... ...
... ... @@ -14,8 +14,6 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
... ... @@ -55,13 +53,10 @@ public class XmlUtils {
{
// 将String类型的xml字符串转成xml
Document document = DocumentHelper.parseText(xmlStr);
Element msg = document.getRootElement();
Element meta = msg.element("META");
String ddtm = meta.elementText("DDTM");
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
ParsePosition pos = new ParsePosition(0);
Date sendDateTime = formatter.parse(ddtm, pos);
Date sendDateTime = DateUtils.strToDateLong(meta.elementText("DDTM"));
XmlData xmlData = XmlData.builder()
.sendContent(msg.elementText("BODY"))
... ...