create XMLGregorianCalendar from String with yyyy-MM-ddT00:00:00 time in java

944 Views Asked by At

I have a problem I need create XMLGregorianCalendar from String like “07.04.2015” with time 00:00:00 in general, for example like is 2015-04-07T00:00:00 what I am doing for this

public static XMLGregorianCalendar getF(String stringDate) {
    XMLGregorianCalendar xgc = null;
    String formatedData = null;
    try {
        SimpleDateFormat in_data = new SimpleDateFormat("dd.MM.yyyy");
        SimpleDateFormat out_data = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        Date date = in_data.parse(stringDate);
        formatedData = out_data.format(date);
        String df = formatedData;
        xgc = DatatypeFactory.newInstance().newXMLGregorianCalendar(df);
    } catch (ParseException ex) {
        ex.printStackTrace();
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }
    return xgc;

}

this code works correctly some results

getF("2015-04-07") -> 2015-04-07T00:00:00
getF("2015-04-07 14:40:49") -> 2015-04-07T00:00:00

however, sometimes this method returns 2015-04-07T01:00:00 I don't know why the time is 01:00:00 time, and not 00:00:00

0

There are 0 best solutions below