Get XMLGregorianCalendar timestamp in format :
2016-01-01T11:58:58-05:00
import java.util.Date;
import java.util.GregorianCalendar;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
public static XMLGregorianCalendar getTimeStamp() throws DatatypeConfigurationException{
Date trailDate=new Date();
XMLGregorianCalendar timestampdate=null;
GregorianCalendar calendar1 = new GregorianCalendar();
calendar1.setTime(trailDate);
try
{
timestampdate=DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar1);
System.out.println("timestampdate :"+timestampdate);
return timestampdate;
}
catch (DatatypeConfigurationException ex)
{
System.out.println("Exception in getting xmlGreg Date, setting bydefault a value for Calender");
return DatatypeFactory.newInstance().newXMLGregorianCalendar("2016-01-01T11:58:58-05:00");
}
}
No comments:
Post a Comment