티스토리 뷰

String형의 일시를 XMLGregorianCalendar의 인스턴스로 변환


/**

 *

 * @param strDate Date(Date format: yyyy-MM-dd hh:mm:ss(e.g. 2016-11-15 09:30:01))

 * @return instance of the XMLGregorianCalendar(Saved date:  2016-11-15T09:30:01)

 * @throws ParseException

 * @throws DatatypeConfigurationException

 */

public static XMLGregorianCalendar strDateToXMLGregorianCalendar(String strDate)

throws ParseException, DatatypeConfigurationException {

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

Calendar calendar = Calendar.getInstance();

Date date = dateFormat.parse(strDate);

calendar.setTime(date);


GregorianCalendar gregorianCalendar = new GregorianCalendar();

gregorianCalendar.setTime(date);

return DatatypeFactory.newInstance().newXMLGregorianCalendar(

gregorianCalendar.get(Calendar.YEAR),

gregorianCalendar.get(Calendar.MONTH) + 1,

gregorianCalendar.get(Calendar.DAY_OF_MONTH),

calendar.get(Calendar.HOUR_OF_DAY),

calendar.get(Calendar.MINUTE),

calendar.get(Calendar.SECOND),

DatatypeConstants.FIELD_UNDEFINED,

DatatypeConstants.FIELD_UNDEFINED

).normalize();

}




'TIL > Java' 카테고리의 다른 글

JDK 21, Virtual Thread 정리  (1) 2025.01.03
GSON Type 정의 관련 정리  (0) 2017.11.21
Marshalling and Unmarshalling by the JAXB  (0) 2016.11.15
injecting XML(Document) into SOAP body(SOAPBody)  (0) 2016.11.15
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함