Example usage for java.util Calendar clear

List of usage examples for java.util Calendar clear

Introduction

In this page you can find the example usage for java.util Calendar clear.

Prototype

public final void clear() 

Source Link

Document

Sets all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined.

Usage

From source file:com.haw3d.jadvalKalemat.net.AbstractDownloader.java

protected static Calendar createDate(int year, int month, int day) {
    Calendar date = Calendar.getInstance();
    date.clear();
    date.set(year, month - 1, day); // Months start at 0 for Calendar!
    return date;//from   www.j a v a 2s  .c o m
}

From source file:io.horizondb.model.core.util.TimeUtils.java

/**
 * Parses the specified <code>String</code> representing a date/time.
 * <p>The supported patterns are: 'yyyy-MM-dd', 'yyyy-MM-dd HH:mm:ss' and 
 * 'yyyy-MM-dd HH:mm:ss.SSS'.</p>/*w  w w  .j a  v  a  2s.  co m*/
 * 
 * @param timeZone the date TimeZone
 * @param dateTime the <code>String</code> representing a date/time.
 * @return the time in millisecond since epoch
 */
public static long parseDateTime(TimeZone timeZone, String dateTime) {

    String pattern = getPattern(dateTime);
    SimpleDateFormat format = new SimpleDateFormat(pattern);

    Calendar calendar = Calendar.getInstance(timeZone);
    calendar.clear();
    calendar.setLenient(false);

    format.setCalendar(calendar);

    Date date = format.parse(dateTime, new ParsePosition(0));

    if (date == null) {
        throw new IllegalArgumentException(format("The value %s cannot be parsed into a valid date", dateTime));
    }
    return date.getTime();
}

From source file:Main.java

/**
 * set to the last day of month// ww  w . j  av  a 2s  .com
 * @param calendar
 */
public static void setToLastDay(Calendar calendar) {
    int year = getYear(calendar);
    int month = getMonth(calendar);
    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    calendar.clear();
    calendar.set(year, month, maxDay);
    calendar.getTimeInMillis();
}

From source file:Main.java

/** accurate to day */
public static Calendar getToday() {
    Calendar cal = Calendar.getInstance();
    int year = getYear(cal);
    int month = getMonth(cal);
    int day = getDay(cal);
    cal.clear();
    cal.set(year, month, day);//from  w  ww  .j  a  va 2s  . c om
    cal.getTimeInMillis();
    return cal;
}

From source file:com.example.geomesa.authorizations.AuthorizationsTutorial.java

/**
 * Creates a base filter that will return a small subset of our results. This can be tweaked to
 * return different results if desired. Currently it should return 16 results.
 *
 * @return/* w w  w .  j av a  2 s  .  com*/
 *
 * @throws CQLException
 * @throws IOException
 */
static Filter createBaseFilter() throws CQLException, IOException {

    // Get a FilterFactory2 to build up our query
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();

    // We are going to query for events in Ukraine during the
    // civil unrest.

    // We'll start by looking at a particular day in February of 2014
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(Calendar.YEAR, 2013);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    Date start = calendar.getTime();

    calendar.set(Calendar.YEAR, 2014);
    calendar.set(Calendar.MONTH, Calendar.APRIL);
    calendar.set(Calendar.DAY_OF_MONTH, 30);
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    Date end = calendar.getTime();
    //        2013-01-01T00:00:00.000Z/2014-04-30T23:00:00.000Z
    Filter timeFilter = ff.between(ff.property(GdeltFeature.Attributes.SQLDATE.getName()), ff.literal(start),
            ff.literal(end));

    // We'll bound our query spatially to Ukraine
    Filter spatialFilter = ff.bbox(GdeltFeature.Attributes.geom.getName(), 31.6, 44, 37.4, 47.75, "EPSG:4326");

    // we'll also restrict our query to only articles about the US, UK or UN
    Filter attributeFilter = ff.like(ff.property(GdeltFeature.Attributes.Actor1Name.getName()), "UNITED%");

    // Now we can combine our filters using a boolean AND operator
    Filter conjunction = ff.and(Arrays.asList(timeFilter, spatialFilter, attributeFilter));

    return conjunction;
}

From source file:ee.ria.xroad.common.signature.BatchSignerIntegrationTest.java

private static Date createDate(int day, int month, int year) {
    Calendar cal = Calendar.getInstance();
    cal.clear(); // Let's clear the current time.
    cal.set(year, month, day);//from   ww w.  ja  v a  2s  .com

    return cal.getTime();
}

From source file:com.spoledge.audao.parser.gql.impl.ParserUtils.java

public static Date date(int year, int month, int day) {
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DAY_OF_MONTH, day);

    return cal.getTime();
}

From source file:com.spoledge.audao.parser.gql.impl.ParserUtils.java

public static Date time(int hour, int minute, int second) {
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);

    return cal.getTime();
}

From source file:com.spoledge.audao.parser.gql.impl.ParserUtils.java

public static Date datetime(int year, int month, int day, int hour, int minute, int second) {
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month - 1);
    cal.set(Calendar.DAY_OF_MONTH, day);
    cal.set(Calendar.HOUR_OF_DAY, hour);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);

    return cal.getTime();
}

From source file:org.globus.workspace.service.impls.site.PilotNotificationUtil.java

static Calendar parseTimestamp(String pilot, String timestamp) throws Exception {

    String errmsg = "non conforming timestamp sent by pilot '" + pilot + "', timestamp = '" + timestamp + "', ";

    if (timestamp == null) {
        throw new Exception(errmsg + "timestamp may not be null");
    }//from  w  w  w  .j ava  2s  .com

    final String[] tokens = timestamp.trim().split("-");

    if (tokens.length != 6) {
        throw new Exception(errmsg + "token length = " + tokens.length);
    }

    final int year;
    final int month;
    final int day;
    final int hour;
    final int minute;
    final int second;
    try {
        year = Integer.parseInt(tokens[0]);
        int mo = Integer.parseInt(tokens[1]);
        month = mo - 1; // Calendar needs month to start from zero
        day = Integer.parseInt(tokens[2]);
        hour = Integer.parseInt(tokens[3]);
        minute = Integer.parseInt(tokens[4]);
        second = Integer.parseInt(tokens[5]);
    } catch (NumberFormatException e) {
        throw new Exception(errmsg + "a token is not an integer");
    }

    // negative numbers are impossible because we split by -

    // calendar is OK with greater numbers than expected (it just
    // increases its internal timestamp by that much); we're not

    if (month > 11) {
        throw new Exception(errmsg + "month > 11");
    }

    if (day > 31) {
        throw new Exception(errmsg + "day > 31");
    }

    if (hour > 23) {
        throw new Exception(errmsg + "hour > 23");
    }

    if (minute > 59) {
        throw new Exception(errmsg + "minute > 59");
    }

    // 61 is intentional, leaps etc...
    if (second > 61) {
        throw new Exception(errmsg + "second > 61");
    }

    final TimeZone tz = new SimpleTimeZone(0, "GMT");
    final Calendar cal = Calendar.getInstance(tz);
    cal.clear();
    cal.set(year, month, day, hour, minute, second);
    return cal;
}