Example usage for java.util Calendar getMinimum

List of usage examples for java.util Calendar getMinimum

Introduction

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

Prototype

public abstract int getMinimum(int field);

Source Link

Document

Returns the minimum value for the given calendar field of this Calendar instance.

Usage

From source file:Main.java

public static void main(String[] args) {

    Calendar cal = Calendar.getInstance();

    // print the minimum value for years
    int min = cal.getMinimum(Calendar.YEAR);
    System.out.println("Minimum Years: " + min);
}

From source file:Main.java

private static void setStartOfMonthToCalendar(Calendar c) {
    c.set(Calendar.DAY_OF_MONTH, c.getMinimum(Calendar.DAY_OF_MONTH));
    setStartOfDayToCalendar(c);//from   w ww.  j av a  2 s .co  m
    Log.d("La Cuenta: ", "Min of Current Month: " + DateFormat.getInstance().format(c.getTime()));
}

From source file:Main.java

public static Calendar newInitializedCalendar() {
    Calendar newitem = Calendar.getInstance();
    newitem.set(Calendar.HOUR, 0);
    newitem.set(Calendar.MINUTE, newitem.getMinimum(Calendar.MINUTE));
    newitem.set(Calendar.SECOND, newitem.getMinimum(Calendar.SECOND));
    newitem.set(Calendar.MILLISECOND, newitem.getMinimum(Calendar.MILLISECOND));
    return newitem;
}

From source file:Main.java

public static String getFirstDayOfMonth(int year, int month) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DATE));
    return new SimpleDateFormat("yyyy-MM-dd ").format(cal.getTime());
}

From source file:org.jahia.utils.DateUtils.java

/**
 * Returns the start of the day (00:00:00:000) for the specified date.
 * /*from w  w  w.  j a  v  a2s  .c o  m*/
 * @param date the date to be processed
 * @return the start of the day (00:00:00:000) for the specified date
 */
public static Calendar dayStart(Calendar date) {
    Calendar c = (Calendar) date.clone();

    c.set(Calendar.HOUR_OF_DAY, c.getMinimum(Calendar.HOUR_OF_DAY));
    c.set(Calendar.MINUTE, c.getMinimum(Calendar.MINUTE));
    c.set(Calendar.SECOND, c.getMinimum(Calendar.SECOND));
    c.set(Calendar.MILLISECOND, c.getMinimum(Calendar.MILLISECOND));

    return c;
}

From source file:com.indoqa.lang.util.TimeUtils.java

public static Date getStartOfDay(Date date, TimeZone timeZone) {
    Calendar calendar = Calendar.getInstance(timeZone);

    calendar.setTime(date);//from  w w  w  . j  a  v a  2 s .  co  m
    for (int eachField : CALENDAR_TIME_FIELDS) {
        calendar.set(eachField, calendar.getMinimum(eachField));
    }

    return calendar.getTime();
}

From source file:DateUtil.java

/**
 * Returns a Date set to the first possible millisecond of the minute.
 * If a null day is passed in, a new Date is created.
 *///from   ww w. j ava 2s.  co  m
public static Date getStartOfMinute(Date day, Calendar cal) {
    if (day == null)
        day = new Date();
    cal.setTime(day);
    cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
    return cal.getTime();
}

From source file:DateUtil.java

/**
 * Returns a Date set to the first possible millisecond of the hour.
 * If a null day is passed in, a new Date is created.
 *///from   w ww.j  a v  a  2  s .c  o m
public static Date getStartOfHour(Date day, Calendar cal) {
    if (day == null)
        day = new Date();
    cal.setTime(day);
    cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
    return cal.getTime();
}

From source file:DateUtil.java

/**
 * Returns a Date set to the first possible millisecond of the day, just
 * after midnight. If a null day is passed in, a new Date is created.
 * midnight (00m 00h 00s)//from w  w  w. j  av  a  2 s . com
 */
public static Date getStartOfDay(Date day, Calendar cal) {
    if (day == null)
        day = new Date();
    cal.setTime(day);
    cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
    return cal.getTime();
}

From source file:org.getobjects.foundation.UDate.java

/**
 * This returns a Calendar object which represents the beginning of the month
 * in the Calendar's locale and timezone.
 * <p>/*  www  .ja v  a  2 s  .  c om*/
 * Eg in a German locale this could be
 *   'Fri, 2007-06-01 00:00:00'
 * if the Calendar being passed in is
 *   'Wed, 2007-06-06 12:34:37'.
 *
 * @param _calendar - a Calendar in the month
 * @return a Calendar representing the start of the month
 */
public static Calendar beginningOfMonthAsCalendar(Calendar _calendar) {
    if (_calendar == null) {
        /* not recommended as the timezone is most likely incorrect */
        _calendar = Calendar.getInstance();
    }

    _calendar.set(Calendar.DAY_OF_MONTH, _calendar.getMinimum(Calendar.DAY_OF_MONTH));
    _calendar.set(Calendar.HOUR_OF_DAY, 0);
    _calendar.set(Calendar.MINUTE, 0);
    _calendar.set(Calendar.SECOND, 0);
    _calendar.set(Calendar.MILLISECOND, 0);
    return _calendar;
}