Here you can find the source of getXmlGregorianCalendar(String unixTime)
Parameter | Description |
---|---|
unixTime | The unixtime. If the argument is null, then epoch is returned. |
public static XMLGregorianCalendar getXmlGregorianCalendar(String unixTime)
//package com.java2s; //License from project: Apache License import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { /**//from www. jav a2 s. com * Turns a string representation of unix time into a XMLGregorianCalendar. * @param unixTime The unixtime. If the argument is null, then epoch is returned. * @return The XMLGregorianCalendar. */ public static XMLGregorianCalendar getXmlGregorianCalendar(String unixTime) { return getXmlGregorianCalendar(getDate(unixTime)); } /** * Turns a date into a XMLGregorianCalendar. * @param date The Date. If the argument is null, then epoch is returned. * @return The XMLGregorianCalendar. */ public static XMLGregorianCalendar getXmlGregorianCalendar(Date date) { if (date == null) { date = new Date(0); } GregorianCalendar gc = new GregorianCalendar(); try { gc.setTime(date); return DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); } catch (Exception e) { throw new IllegalStateException("Could not convert the date '" + date + "' into the xml format.", e); } } /** * Creates a Date object from the string representation of unixtime in seconds. * @param unixTime the unixtime. If the argument is null, then epoch is returned. */ public static Date getDate(String unixTime) { Date date; if (unixTime == null) { date = new Date(0); } else { date = new Date(Long.parseLong(unixTime) * 1000); } return date; } }