/** * Sets the month with 1-index, e.g. 1=the first day of the month */ public BaseDateTimeDt setDay(int theDay) { setFieldValue(Calendar.DAY_OF_MONTH, theDay, null, 0, 31); return this; }
/** * Sets the milliseconds within the current second. * <p> * Note that this method sets the * same value as {@link #setNanos(long)} but with less precision. * </p> */ public BaseDateTimeDt setMillis(int theMillis) { setFieldValue(Calendar.MILLISECOND, theMillis, null, 0, 999); return this; }
/** * Sets the minute of the hour in the range 0-59 */ public BaseDateTimeDt setMinute(int theMinute) { setFieldValue(Calendar.MINUTE, theMinute, null, 0, 59); return this; }
/** * Sets the second of the minute in the range 0-59 */ public BaseDateTimeDt setSecond(int theSecond) { setFieldValue(Calendar.SECOND, theSecond, null, 0, 59); return this; }
/** * Sets the hour of the day in a 24h clock, e.g. 13=1pm */ public BaseDateTimeDt setHour(int theHour) { setFieldValue(Calendar.HOUR_OF_DAY, theHour, null, 0, 23); return this; }
/** * Sets the month with 0-index, e.g. 0=January */ public BaseDateTimeDt setMonth(int theMonth) { setFieldValue(Calendar.MONTH, theMonth, null, 0, 11); return this; }
/** * Sets the year, e.g. 2015 */ public BaseDateTimeDt setYear(int theYear) { setFieldValue(Calendar.YEAR, theYear, null, 0, 9999); return this; }
/** * Sets the nanoseconds within the current second * <p> * Note that this method sets the * same value as {@link #setMillis(int)} but with more precision. * </p> */ public BaseDateTimeDt setNanos(long theNanos) { validateValueInRange(theNanos, 0, NANOS_PER_SECOND-1); String fractionalSeconds = StringUtils.leftPad(Long.toString(theNanos), 9, '0'); // Strip trailing 0s for (int i = fractionalSeconds.length(); i > 0; i--) { if (fractionalSeconds.charAt(i-1) != '0') { fractionalSeconds = fractionalSeconds.substring(0, i); break; } } int millis = (int)(theNanos / NANOS_PER_MILLIS); setFieldValue(Calendar.MILLISECOND, millis, fractionalSeconds, 0, 999); return this; }
/** * Sets the hour of the day in a 24h clock, e.g. 13=1pm */ public BaseDateTimeDt setHour(int theHour) { setFieldValue(Calendar.HOUR_OF_DAY, theHour, null, 0, 23); return this; }
/** * Sets the second of the minute in the range 0-59 */ public BaseDateTimeDt setSecond(int theSecond) { setFieldValue(Calendar.SECOND, theSecond, null, 0, 59); return this; }
/** * Sets the minute of the hour in the range 0-59 */ public BaseDateTimeDt setMinute(int theMinute) { setFieldValue(Calendar.MINUTE, theMinute, null, 0, 59); return this; }
/** * Sets the year, e.g. 2015 */ public BaseDateTimeDt setYear(int theYear) { setFieldValue(Calendar.YEAR, theYear, null, 0, 9999); return this; }
/** * Sets the month with 1-index, e.g. 1=the first day of the month */ public BaseDateTimeDt setDay(int theDay) { setFieldValue(Calendar.DAY_OF_MONTH, theDay, null, 0, 31); return this; }
/** * Sets the milliseconds within the current second. * <p> * Note that this method sets the * same value as {@link #setNanos(long)} but with less precision. * </p> */ public BaseDateTimeDt setMillis(int theMillis) { setFieldValue(Calendar.MILLISECOND, theMillis, null, 0, 999); return this; }
/** * Sets the month with 0-index, e.g. 0=January */ public BaseDateTimeDt setMonth(int theMonth) { setFieldValue(Calendar.MONTH, theMonth, null, 0, 11); return this; }
/** * Sets the nanoseconds within the current second * <p> * Note that this method sets the * same value as {@link #setMillis(int)} but with more precision. * </p> */ public BaseDateTimeDt setNanos(long theNanos) { validateValueInRange(theNanos, 0, NANOS_PER_SECOND-1); String fractionalSeconds = StringUtils.leftPad(Long.toString(theNanos), 9, '0'); // Strip trailing 0s for (int i = fractionalSeconds.length(); i > 0; i--) { if (fractionalSeconds.charAt(i-1) != '0') { fractionalSeconds = fractionalSeconds.substring(0, i); break; } } int millis = (int)(theNanos / NANOS_PER_MILLIS); setFieldValue(Calendar.MILLISECOND, millis, fractionalSeconds, 0, 999); return this; }