Example usage for java.util GregorianCalendar getTime

List of usage examples for java.util GregorianCalendar getTime

Introduction

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

Prototype

public final Date getTime() 

Source Link

Document

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

Usage

From source file:Main.java

/**
 * Parse an xs:dateTime value in "2009-05-21T14:52:18-07:00" format (with the timezone).
 * // w  w w  . j a  va2 s. c om
 * @param timestamp
 *            The xs:dateTime
 * @return The converted date
 * @throws DatatypeConfigurationException
 *             For errors.
 */
public static Date parseXmlDateTimeWithZone(String timestamp) throws DatatypeConfigurationException {
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(timestamp);
    GregorianCalendar gregorianCalendar = xmlGregorianCalendar.toGregorianCalendar();
    return gregorianCalendar.getTime();
}

From source file:org.sonar.plugins.dbcleaner.period.Periods.java

static Date getDate(Configuration conf, String propertyKey, String defaultNumberOfMonths) {
    int months = conf.getInt(propertyKey, Integer.parseInt(defaultNumberOfMonths));
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.add(GregorianCalendar.MONTH, -months);
    return calendar.getTime();
}

From source file:net.darkmist.clf.LogEntryTest.java

private static final Date mkStaticDate() {
    GregorianCalendar cal = new GregorianCalendar(2007, 5, 5, 8, 9, 10);
    cal.setTimeZone(TimeZone.getTimeZone("GMT-1"));
    return cal.getTime();
}

From source file:Main.java

/**
 * Returns a date instance for a given timestamp string that complies to the
 * RFC 822 standard//ww  w  .j  a  va  2  s  .c  om
 * 
 * @param rfc822DateString
 * @return
 * @throws DatatypeConfigurationException
 */
public static Date getDate(String rfc822DateString) throws DatatypeConfigurationException {
    // SimpleDateFormat can't handle RFC822 (-04:00 instead of GMT-04:00)
    // date formats
    //
    // SimpleDateFormat dateFormat = new
    // SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    // return dateFormat.parse(propertyNode.asString());
    GregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(rfc822DateString)
            .toGregorianCalendar();
    return calendar.getTime();
}

From source file:Main.java

private static Date calculate(Date d, int field, int amount) {
    if (d == null)
        return null;
    GregorianCalendar g = new GregorianCalendar();
    g.setGregorianChange(d);//w  ww . ja  v a  2 s .c  o m
    g.add(field, amount);
    return g.getTime();
}

From source file:Main.java

public static int toH(long time) {
    Date dat = new Date(time);
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(dat);//from   www . j av a 2  s  . com
    java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("HH");
    String sb = format.format(gc.getTime());
    int i = Integer.parseInt(sb);
    return i;
}

From source file:Main.java

public static int toTimeM(long time) {
    Date dat = new Date(time);
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(dat);//w  w  w .ja v a2s .c  om
    java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("mm");
    String sb = format.format(gc.getTime());
    int i = Integer.parseInt(sb);
    return i;
}

From source file:Main.java

public static String toHM(long time) {
    Date dat = new Date(time);
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(dat);//from w w w . j  a  va  2s  . com
    java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("HH:mm");
    String sb = format.format(gc.getTime());
    return sb;
}

From source file:Main.java

public static int toM(long time) {
    Date dat = new Date(time);
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(dat);/*from w  ww.  ja  va  2s .c o m*/
    java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("mm");
    String sb = format.format(gc.getTime());
    int i = Integer.parseInt(sb);
    return i;

}

From source file:DateUtils.java

/**
 * A method to get the current date to use in a timestamp
 *
 * @return  a string containing the timestamp
 *//*from w  w w . ja  v  a  2 s.co m*/
public static String getCurrentDate() {

    GregorianCalendar calendar = new GregorianCalendar();
    DateFormat formatter = DateFormat.getDateInstance(DateFormat.FULL);

    return formatter.format(calendar.getTime());

}