Java Code Examples for java.util.Calendar#getMinimum()

The following examples show how to use java.util.Calendar#getMinimum() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSMPPGateway.java    From smslib-v3 with Apache License 2.0 6 votes vote down vote up
private String formatTimeFromHours(int timeInHours)
{
	if (timeInHours < 0) { return null; }
	Calendar cDate = Calendar.getInstance();
	cDate.clear();
	cDate.set(Calendar.YEAR, 0);
	cDate.add(Calendar.HOUR, timeInHours);
	int years = cDate.get(Calendar.YEAR) - cDate.getMinimum(Calendar.YEAR);
	int months = cDate.get(Calendar.MONTH);
	int days = cDate.get(Calendar.DAY_OF_MONTH) - 1;
	int hours = cDate.get(Calendar.HOUR_OF_DAY);
	String yearsString = (years < 10) ? "0" + years : years + "";
	String monthsString = (months < 10) ? "0" + months : months + "";
	String daysString = (days < 10) ? "0" + days : days + "";
	String hoursString = (hours < 10) ? "0" + hours : hours + "";
	return yearsString + monthsString + daysString + hoursString + "0000000R";
}
 
Example 2
Source File: DateUtil.java    From easyweb-shiro with MIT License 5 votes vote down vote up
/**
 * 得到当月第一天
 * @return
 */
public static Date getFirstDayOfMonth() {
	Calendar cal = Calendar.getInstance();
	int firstDay = cal.getMinimum(Calendar.DAY_OF_MONTH);
	cal.set(Calendar.DAY_OF_MONTH, firstDay);
	return cal.getTime();
}
 
Example 3
Source File: DateUtil.java    From easyweb-shiro with MIT License 5 votes vote down vote up
/**
 * 得到下月的第一天
 * @return
 */
public static Date getFirstDayOfNextMonth() {
	Calendar cal = Calendar.getInstance();
	cal.add(Calendar.MONTH, +1);
	int firstDay = cal.getMinimum(Calendar.DAY_OF_MONTH);
	cal.set(Calendar.DAY_OF_MONTH, firstDay);
	return cal.getTime();
}
 
Example 4
Source File: ChartMeasurementView.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
private void setViewMode(final ViewMode mode) {
    viewMode = mode;
    Calendar viewModeCalender = Calendar.getInstance();
    viewModeCalender.setTime(lastMeasurement.getDateTime());

    switch (mode) {
        case DAY_OF_MONTH:
            minXValue = viewModeCalender.getMinimum(Calendar.DAY_OF_MONTH);
            maxXValue = viewModeCalender.getMaximum(Calendar.DAY_OF_MONTH);
            break;
        case WEEK_OF_MONTH:
            minXValue = 1;
            maxXValue = viewModeCalender.getActualMaximum(Calendar.WEEK_OF_MONTH);
            break;
        case WEEK_OF_YEAR:
            minXValue = viewModeCalender.getActualMinimum(Calendar.WEEK_OF_YEAR);
            maxXValue = viewModeCalender.getActualMaximum(Calendar.WEEK_OF_YEAR);
            break;
        case MONTH_OF_YEAR:
            minXValue = viewModeCalender.getActualMinimum(Calendar.MONTH);
            maxXValue = viewModeCalender.getActualMaximum(Calendar.MONTH);
            break;
        case DAY_OF_YEAR:
            minXValue = viewModeCalender.getActualMinimum(Calendar.DAY_OF_YEAR);
            maxXValue = viewModeCalender.getActualMaximum(Calendar.DAY_OF_YEAR);
            break;
        case DAY_OF_ALL:
        case WEEK_OF_ALL:
        case MONTH_OF_ALL:
        case YEAR_OF_ALL:
            minXValue = convertDateInShort(firstMeasurement.getDateTime());
            maxXValue = convertDateInShort(lastMeasurement.getDateTime());
            break;
        default:
            throw new IllegalArgumentException("view mode not implemented");
    }

    setXValueFormat(mode);
}
 
Example 5
Source File: DateRangePrefixTree.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private static int calFieldLen(Calendar cal, int field) {
  return cal.getMaximum(field) - cal.getMinimum(field) + 1;
}
 
Example 6
Source File: DateUtils.java    From cms with Apache License 2.0 3 votes vote down vote up
/**
 * 得到格式化后的当月第一天,格式为yyyy-MM-dd,如2006-02-01
 *
 * @param currDate
 *            要格式化的日期
 * @see Calendar#getMinimum(int)
 * @see #getFormatDate(Date, String)
 * @return String 返回格式化后的当月第一天,格式为yyyy-MM-dd,如2006-02-01
 */
public static String getFirstDayOfMonth() {
	Calendar cal = Calendar.getInstance();
	int firstDay = cal.getMinimum(Calendar.DAY_OF_MONTH);
	cal.set(Calendar.DAY_OF_MONTH, firstDay);
	return getFormatDate(cal.getTime(), DATE_FORMAT);
}
 
Example 7
Source File: DateUtils.java    From cms with Apache License 2.0 3 votes vote down vote up
/**
 * 得到格式化后的下月第一天,格式为yyyy-MM-dd,如2006-02-01
 *
 * @param currDate
 *            要格式化的日期
 * @see Calendar#getMinimum(int)
 * @see #getFormatDate(Date, String)
 * @return String 返回格式化后的下月第一天,格式为yyyy-MM-dd,如2006-02-01
 */
public static String getFirstDayOfNextMonth() {
	Calendar cal = Calendar.getInstance();
	cal.add(Calendar.MONTH, +1);
	int firstDay = cal.getMinimum(Calendar.DAY_OF_MONTH);
	cal.set(Calendar.DAY_OF_MONTH, firstDay);
	return formatDate(cal.getTime());
}