I am using google data api which gives date in datetime format. I want to convert this DateTime format date in Gregorian calendar date format. Does anyone know any methods for doing this?
**Edited the question*
That class is definitely not Google's best work (I link to the API so I can confirm we are talking about the same class and version). Here is what I would do:
public class DateTimeConverter extends DateTime {
private DateTime originalTime;
public DateTimeConverter(DateTime originalTime) {
this.originalTime = originalTime;
}
public java.util.Date getDate() {
return new java.util.Date(this.value);
}
}
Sample usage:
DateTime originalTime;
//Populate variable and then:
java.util.Date myDate = new DateTimeConverter(originalTime).getDate();
From there you can make a Calendar. Dealing with what to do if the DateTime represents a Date only, and timezone issues, you can deal with from there (I don't know your requirements) but if you have to get serious about it, use JodaTime to handle this as much as possible.
Also check this
public static XMLGregorianCalendar getGregorianDate(Date date) {
XMLGregorianCalendar xMLGregorianCalendar = null;
try {
GregorianCalendar c = new GregorianCalendar();
c.setTime(date);
xMLGregorianCalendar = DatatypeFactory.newInstance()
.newXMLGregorianCalendar(c);
} catch (Exception e) {
e.printStackTrace();
}
return xMLGregorianCalendar;
}
public static Date getDate(XMLGregorianCalendar xmlGregorianCalendar) {
Date date = xmlGregorianCalendar.toGregorianCalendar().getTime();
return date;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With