Example usage for java.util GregorianCalendar setTime

List of usage examples for java.util GregorianCalendar setTime

Introduction

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

Prototype

public final void setTime(Date date) 

Source Link

Document

Sets this Calendar's time with the given Date.

Usage

From source file:Main.java

public static XMLGregorianCalendar xmlGregorianCalendar(Date date) throws DatatypeConfigurationException {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date);
    return DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
}

From source file:Main.java

/**
 *
 * @return/* w w  w . jav a  2s .co  m*/
 */
public static String tomorrow() {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(new Date());
    gc.add(GregorianCalendar.DATE, 1);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    return sdf.format(gc.getTime());
}

From source file:Main.java

public static GregorianCalendar getCalendar(Date day) {
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTime(day);
    return gregorianCalendar;
}

From source file:Main.java

/**
 * Remove the time of a date value/*from  w w w.j ava2  s  .co  m*/
 *
 * @param date Date to remove the time part
 * @return A date with its time set to 00:00:00
 */
public static Date removeTime(Date date) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);
    gc.set(Calendar.HOUR_OF_DAY, 0);
    gc.set(Calendar.MINUTE, 0);
    gc.set(Calendar.SECOND, 0);
    gc.set(Calendar.MILLISECOND, 0);
    return gc.getTime();
}

From source file:Main.java

public static GregorianCalendar getGregorianCalendarFromEsmartString(String _esmart) {
    GregorianCalendar res = new GregorianCalendar();
    res.setTime(getDateFromEsmartString(_esmart));
    return res;//from ww w  .  java 2s  .  c o  m
}

From source file:Main.java

/**
 * Format a date in xs:dateTime format.//from ww w . j a  v  a2 s.  c  om
 * 
 * @param date
 *            The date.
 * @return The xs:dateTime
 * @throws DatatypeConfigurationException
 *             For errors.
 */
public static String formatXmlDateTimeWithZone(Date date) throws DatatypeConfigurationException {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(gc);
    return xmlGregorianCalendar.toXMLFormat();
}

From source file:Main.java

public static XMLGregorianCalendar getXmlGregorianCalendarFromDate(Date date) {

    GregorianCalendar cal = new GregorianCalendar();
    cal.setTime(date);

    XMLGregorianCalendar f = null;
    try {/*from w  w w . j a va 2 s . co  m*/
        f = DatatypeFactory.newInstance().newXMLGregorianCalendar(cal);
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
    }

    return f;
}

From source file:Main.java

public static XMLGregorianCalendar toXMLGregorianCalendarByTimeZone(Date date, TimeZone timeZone) {
    if (date == null)
        return null;
    GregorianCalendar calendar = new GregorianCalendar(timeZone);
    calendar.setTime(date);
    return newInstance.newXMLGregorianCalendar(calendar);
}

From source file:Main.java

public static XMLGregorianCalendar toXmlDate(Date date) {
    try {/* w w w.j  a v  a  2  s  . c o  m*/
        GregorianCalendar c = new GregorianCalendar();
        c.setTime(date);
        return DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    } catch (DatatypeConfigurationException dtce) {
        throw new UnsupportedOperationException("Nemohu prevest " + "GregorianCalendar na XMLGregorianCalendar",
                dtce);
    }
}

From source file:Main.java

public static String timeFormat(long date, String format) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(new Date(date));
    java.text.SimpleDateFormat fm = null;
    if (format != null) {
        fm = new java.text.SimpleDateFormat(format);
    } else {//w  ww  . j  a v  a  2 s  .c om
        fm = new java.text.SimpleDateFormat(DEFAULT_FORMAT);
    }
    return fm.format(gc.getTime());
}