Example usage for java.util Calendar set

List of usage examples for java.util Calendar set

Introduction

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

Prototype

public void set(int field, int value) 

Source Link

Document

Sets the given calendar field to the given value.

Usage

From source file:com.oncecorp.visa3d.bridge.utility.JdbcUtils.java

/**
 * This method converts the java date into the long that point to the beginning
 * of the day.// www.  j  a va 2 s  .c  o m
 * @param date The converted date object.
 * @param startEnd <tt>true</tt> day start time, <tt>false</tt> day end time.
 * @return The long that point to the beginning or end of the day.
 */
public static long dayValue(Date date, boolean startEnd) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.HOUR, startEnd ? 0 : 23);
    calendar.set(Calendar.MINUTE, startEnd ? 0 : 59);
    calendar.set(Calendar.SECOND, startEnd ? 0 : 59);
    calendar.set(Calendar.MILLISECOND, startEnd ? 0 : 999);
    return calendar.getTime().getTime();
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.DateUtils.java

/**
 * Return the next day from the given day (the next day at 00:00)
 *
 * @param day the day to calculate the next day for
 * @return the next day from the given day
 *///from ww  w.j  a  va 2  s  .c o m
public static Calendar getNextDayFrom(final Calendar day) {

    day.set(Calendar.HOUR_OF_DAY, 0);
    day.set(Calendar.MINUTE, 0);
    day.set(Calendar.SECOND, 0);
    day.set(Calendar.MILLISECOND, 0);

    // Next day
    day.add(Calendar.DAY_OF_YEAR, 1);

    return day;
}

From source file:eu.annocultor.converters.solr.SolrPeriodsTagger.java

static Date endOfDay(Date date) {
    if (date == null) {
        return null;
    }/*ww  w  . j a v a  2  s.c o m*/
    Calendar calendar = GregorianCalendar.getInstance(TimeZone.getTimeZone("UTC"));
    calendar.setTime(date);
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    return calendar.getTime();
}

From source file:Main.java

public static long getPeriodStart(int periodType, long date) {
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(date);/*w  w  w  .  j  a v  a2  s  . c o m*/

    switch (periodType) {
    case TYPE_DAY: {
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        break;
    }

    case TYPE_WEEK: {
        cal.setFirstDayOfWeek(Calendar.MONDAY);
        final int currentDayOfWeek = (cal.get(Calendar.DAY_OF_WEEK) + 7 - cal.getFirstDayOfWeek()) % 7;
        cal.add(Calendar.DAY_OF_YEAR, -currentDayOfWeek);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        break;
    }

    case TYPE_MONTH: {
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        break;
    }

    case TYPE_YEAR: {
        cal.set(Calendar.MONTH, 0);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        break;
    }
    }
    return cal.getTimeInMillis();
}

From source file:Main.java

/**
 * Get the date for the given values.// w w w .  j a  v  a  2  s .  c  o  m
 *
 * @param day
 *            The day.
 * @param month
 *            The month.
 * @param year
 *            The year.
 * @return The date represented by the given values.
 */
private static Date getDate(int day, int month, int year) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DATE, day);
    return cal.getTime();
}

From source file:com.ekom.ekomerp.global.DateTimeUtils.java

public static Calendar getCalendarWithoutTime(Date date, Locale locale) {
    Calendar calendar = Calendar.getInstance(locale);
    calendar.setTime(date);//from w ww. j  a  va2s . co  m
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar;
}

From source file:es.tekniker.framework.ktek.util.Utils.java

public static long getTimeinMillis4FullDateTimeGMT(int year, int month, int day, int hours, int minutes,
        int seconds) {
    Calendar c = getCalendarGMT();

    c.set(Calendar.YEAR, year);
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DAY_OF_MONTH, day);

    c.set(Calendar.HOUR_OF_DAY, hours);
    c.set(Calendar.MINUTE, minutes);
    c.set(Calendar.SECOND, seconds);

    System.out.println("New Time: " + c.getTime());

    long timeinmillis = c.getTimeInMillis();
    System.out.println(" system time in millis " + timeinmillis);

    return timeinmillis;
}

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/*from  w  w w .  j  a va 2 s  .  c  om*/
 *
 * @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:com.qdum.llhb.common.utils.DateUtils.java

/**
 * getMonthLastDay??:???/*from  ww w  . j  a  v a 2s.  c  om*/
 *
 * @author yaoyt
 * @time 15/12/29 ?1:21
 */
public static Date getMonthLastDay() {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
    return c.getTime();
}

From source file:com.qdum.llhb.common.utils.DateUtils.java

/**
  * ?/*www  .jav a 2 s .c  o  m*/
  *
  * @param d
  * @param day
  * @return
  */
public static String getDateAfter(int day) {
    Calendar now = Calendar.getInstance();
    now.set(Calendar.DATE, now.get(Calendar.DATE) + day);
    return formatDate(now.getTime(), "yyyy-MM-dd HH:mm:ss");
}