Example usage for java.util GregorianCalendar getInstance

List of usage examples for java.util GregorianCalendar getInstance

Introduction

In this page you can find the example usage for java.util GregorianCalendar getInstance.

Prototype

public static Calendar getInstance() 

Source Link

Document

Gets a calendar using the default time zone and locale.

Usage

From source file:com.rogers.ute.creditservice.util.CreditServiceUtils.java

private static XMLGregorianCalendar asXMLGregorianCalendar(String date) {
    try {/*from  w  w w.  ja v  a 2s.  c o m*/
        XMLGregorianCalendar result = null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
        /*Date date = simpleDateFormat.parse(date);*/
        gregorianCalendar.setTime(simpleDateFormat.parse(date));
        result = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
        return result;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

/**
 *  Convert date from String to Xml GregorianCalendar in this 'MM/dd/yyyy hh:mm:ss'
 * @param s//from ww w.  j  a v  a  2 s .  c  o m
 * @return
 * @throws DatatypeConfigurationException
 * @throws ParseException
 */
public static XMLGregorianCalendar stringToXMLGregorianCalendar(String s)
        throws DatatypeConfigurationException, ParseException {
    if (s != null && !(s.trim().length() < 1)) {
        XMLGregorianCalendar result = null;
        Date date;
        SimpleDateFormat simpleDateFormat;
        GregorianCalendar gregorianCalendar;

        simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
        date = simpleDateFormat.parse(s);
        gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
        gregorianCalendar.setTime(date);
        result = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
        return result;

    }
    return null;
}