Current Date in GregorianCalendar using java
Code snippet that will give Current date in GregorianCalendar format:
import java.util.GregorianCalendar;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
public class CurrentDate {
public CurrentDate() {
super();
}
public static void main(String[] args) {
XMLGregorianCalendar xgcal = null;
try {
GregorianCalendar gcal =
(GregorianCalendar)GregorianCalendar.getInstance();
xgcal =
DatatypeFactory.newInstance().newXMLGregorianCalendar(gcal);
System.out.println(“xgcal “+xgcal.toString());
} catch (DatatypeConfigurationException dce) {
System.out.println(“Exception occurred while getting XMLGregorianCalendar “+dce);
}
}
}