Example usage for java.util GregorianCalendar setTimeInMillis

List of usage examples for java.util GregorianCalendar setTimeInMillis

Introduction

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

Prototype

public void setTimeInMillis(long millis) 

Source Link

Document

Sets this Calendar's current time from the given long value.

Usage

From source file:Main.java

/**
 * Gets the XML Gregorian calendar from date.
 *
 * @param date the date./*  w  w  w.  j  av a2  s .c om*/
 *
 * @return the XML Gregorian calendar.
 */
public static XMLGregorianCalendar getXMLDate(Date date) {
    DatatypeFactory dataTypeFactory;
    try {
        dataTypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new RuntimeException(e);
    }
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTimeInMillis(date.getTime());
    return dataTypeFactory.newXMLGregorianCalendar(gc);
}

From source file:Main.java

/**
 * Converts a java.util.Date into an instance of XMLGregorianCalendar
 *
 * @param date Instance of java.util.Date or a null reference
 * @return XMLGregorianCalendar instance whose value is based upon the
 * value in the date parameter. If the date parameter is null then
 * this method will simply return null.//from  ww w  .ja v  a 2 s . co  m
 */
public static XMLGregorianCalendar dateAsCalendar(Date date) {
    if (date == null) {
        return null;
    } else {
        GregorianCalendar gc = new GregorianCalendar();
        gc.setTimeInMillis(date.getTime());
        return df.newXMLGregorianCalendar(gc);
    }
}

From source file:Main.java

/**
 * Converts a <code>java.util.Date</code> instance to a
 * <code>javax.xml.datatype.XMLGregorianCalendar</code> instance.
 *
 * @param date the <code>java.util.Date</code> instance to convert
 *
 * @return the converted <code>javax.xml.datatype.XMLGregorianCalendar</code> instance
 *//*w  ww  .j  a  v a  2 s . c  o  m*/
public static XMLGregorianCalendar asXMLGregorianCalendar(java.util.Date date) {
    if (date == null) {
        return null;
    } else {
        GregorianCalendar calendar = new GregorianCalendar();

        calendar.setTimeInMillis(date.getTime());

        return datatypeFactory.newXMLGregorianCalendar(calendar);
    }
}

From source file:Main.java

public static XMLGregorianCalendar parse(long time, int timezone) {
    GregorianCalendar cal = new GregorianCalendar();

    cal.setTimeInMillis(time);
    XMLGregorianCalendar xCal = null;
    try {/*from   www.java 2 s  .  co m*/
        xCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
        xCal.setTimezone(timezone);
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }

    return xCal;
}

From source file:Main.java

public static long convertTime(long time) {
    GregorianCalendar t1 = new GregorianCalendar(TimeZone.getTimeZone("America/Los_Angeles"));
    t1.setTimeInMillis(time);
    GregorianCalendar t2 = new GregorianCalendar();
    t2.set(t1.get(GregorianCalendar.YEAR), t1.get(GregorianCalendar.MONTH),
            t1.get(GregorianCalendar.DAY_OF_MONTH), t1.get(GregorianCalendar.HOUR_OF_DAY),
            t1.get(GregorianCalendar.MINUTE), t1.get(GregorianCalendar.SECOND));
    return t2.getTimeInMillis();
}

From source file:org.sifassociation.util.SIFAuthUtil.java

public static XMLGregorianCalendar stringToXMLGregorianCalendar(String timestamp)
        throws DatatypeConfigurationException {
    Calendar calendar = DatatypeConverter.parseDateTime(timestamp);
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTimeInMillis(calendar.getTimeInMillis());
    return DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
}

From source file:com.aes.touresbalon.touresbalonoms.utilities.OmsUtil.java

public static XMLGregorianCalendar stringToXMLGreogrianCalendar(Date fecha)
        throws ParseException, DatatypeConfigurationException {
    //        DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
    //        Date fechaUtil = formatter.parse(fecha);
    GregorianCalendar gc = new GregorianCalendar();
    DatatypeFactory df = DatatypeFactory.newInstance();
    gc.setTimeInMillis(fecha.getTime());
    return df.newXMLGregorianCalendar(gc);
}

From source file:DateUtils.java

/**
 * Converts a given time in milliseconds into a {@link XMLGregorianCalendar} object.
 * <p>//from w ww . j a v a2s  .c  o m
 * The input milliseconds value represents the specified number of milliseconds since the standard base time known
 * as "the epoch", namely January 1, 1970, 00:00:00 GMT.
 *
 * @param date
 *            A given time corresponding to the number of milliseconds since January 1, 1970, 00:00:00 GMT
 * @return A new instance of <code>XMLGregorianCalendar</code> representing the input time
 */
public static XMLGregorianCalendar toXmlGregorianCalendar(final long date) {
    try {
        final GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTimeInMillis(date);
        return DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
    } catch (final DatatypeConfigurationException ex) {
        System.out.println("Unable to convert date '%s' to an XMLGregorianCalendar object");
    }
}

From source file:org.apache.ranger.common.DateUtil.java

public static Date getLocalDateForUTCDate(Date date) {
    Calendar local = Calendar.getInstance();
    int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
    GregorianCalendar utc = new GregorianCalendar();
    utc.setTimeInMillis(date.getTime());
    utc.add(Calendar.MILLISECOND, offset);
    return utc.getTime();
}

From source file:org.apache.ranger.common.DateUtil.java

public static Date getUTCDate() {
    try {// w ww  .  ja va2  s.  com
        Calendar local = Calendar.getInstance();
        int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
        GregorianCalendar utc = new GregorianCalendar(gmtTimeZone);
        utc.setTimeInMillis(local.getTimeInMillis());
        utc.add(Calendar.MILLISECOND, -offset);
        return utc.getTime();
    } catch (Exception ex) {
        return null;
    }
}