List of usage examples for java.util Calendar clear
public final void clear()
Calendar
undefined. From source file:org.activiti.designer.property.extension.field.CustomPropertyDatePickerField.java
@Override public void refresh() { final String value = getSimpleValueOrDefault(); if (StringUtils.isNotBlank(value)) { Date date;/*from w ww .ja v a 2 s . c o m*/ try { date = sdf.parse(value); final Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setTime(date); // set fields calendarControl.setYear(calendar.get(Calendar.YEAR)); calendarControl.setMonth(calendar.get(Calendar.MONTH)); calendarControl.setDay(calendar.get(Calendar.DAY_OF_MONTH)); calendarControl.setHours(calendar.get(Calendar.HOUR_OF_DAY)); calendarControl.setMinutes(calendar.get(Calendar.MINUTE)); calendarControl.setSeconds(calendar.get(Calendar.SECOND)); } catch (ParseException e) { e.printStackTrace(); } } }
From source file:org.spring.data.gemfire.app.beans.Person.java
protected Calendar getCalendar(final long timeInMillis) { Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setTimeInMillis(timeInMillis); return calendar; }
From source file:com.stevpet.sonar.plugins.dotnet.mscover.datefilter.CutOffDateFilter.java
private Date getGenesis() { Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(1970, 1, 1);//from ww w . j av a2s . c o m return calendar.getTime(); }
From source file:org.jvnet.hudson.plugins.thinbackup.utils.TestUtils.java
@Test public void testGetDateFromValidBackupDir() { final Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(2011, 1, 13, 10, 48);/*from ww w . j av a2 s . c om*/ final Date expected = cal.getTime(); String displayDate = "FULL-2011-02-13_10-48"; Date tmp = Utils.getDateFromBackupDirectoryName(displayDate); Assert.assertNotNull(tmp); Assert.assertEquals(expected, tmp); displayDate = "DIFF-2011-02-13_10-48"; tmp = Utils.getDateFromBackupDirectoryName(displayDate); Assert.assertNotNull(tmp); Assert.assertEquals(expected, tmp); }
From source file:com.feilong.core.date.DateUtil.java
/** * <code>date</code> <code>week</code>. * /*from w w w . j a v a2 s . com*/ * <pre class="code"> * 2015-7-29 14:08 * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.FRIDAY) =2015-01-02 00:00:00.000 * DateUtil.getFirstWeekOfSpecifyDateYear(NOW, Calendar.MONDAY) =2015-01-05 00:00:00.000 * </pre> * * <p> * {@link Calendar#DAY_OF_WEEK_IN_MONTH} ?. DAY_OF_WEEK ,???.<br> * {@link Calendar#WEEK_OF_MONTH} {@link Calendar#WEEK_OF_YEAR} ??,?? {@link Calendar#getFirstDayOfWeek()} * {@link Calendar#getMinimalDaysInFirstWeek()}. * </p> * * <p> * DAY_OF_MONTH 1 7 DAY_OF_WEEK_IN_MONTH 1;<br> * 8 14 DAY_OF_WEEK_IN_MONTH 2,?.<br> * DAY_OF_WEEK_IN_MONTH 0 DAY_OF_WEEK_IN_MONTH 1 ?.<br> * ?,,? DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1.<br> * ?,????.<br> * , 31 , DAY_OF_WEEK_IN_MONTH -1 DAY_OF_WEEK_IN_MONTH 5 DAY_OF_WEEK_IN_MONTH 4 ?? * </p> * * @param date * * @param week * 1 ?2 3 4 5 6 7, ? {@link Calendar#SUNDAY}, {@link Calendar#MONDAY}, {@link Calendar#TUESDAY}, * {@link Calendar#WEDNESDAY}, {@link Calendar#THURSDAY}, {@link Calendar#FRIDAY}, {@link Calendar#SATURDAY} * @return <code>date</code> null, {@link NullPointerException} * @see Calendar#SUNDAY * @see Calendar#MONDAY * @see Calendar#TUESDAY * @see Calendar#WEDNESDAY * @see Calendar#THURSDAY * @see Calendar#FRIDAY * @see Calendar#SATURDAY * @since 1.3.0 */ public static Date getFirstWeekOfSpecifyDateYear(Date date, int week) { Calendar calendar = toCalendar(date); calendar.clear(); calendar.set(Calendar.YEAR, getYear(date)); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, 1); calendar.set(Calendar.DAY_OF_WEEK, week); return CalendarUtil.toDate(calendar); }
From source file:org.apache.vysper.xmpp.datetime.DateTimeProfile.java
/** * Parses a time, compliant with ISO-8601 and XEP-0082. * @param time The time string// w w w.j a v a 2 s . co m * @return A {@link Calendar} representing the time, in the * time zone specified by the input string. If a time zone is not specified * in the input string, the returned {@link Calendar} will be in the UTC time zone * @throws IllegalArgumentException If the input string is not a valid time */ public Calendar fromTime(String time) { Matcher matcher = TIME_PATTERN.matcher(time); if (matcher.find()) { int hour = Integer.valueOf(matcher.group(1)); int minute = Integer.valueOf(matcher.group(2)); int second = Integer.valueOf(matcher.group(3)); String tzValue = matcher.group(4); TimeZone tz; if (tzValue == null || tzValue.equals("Z")) { tz = TIME_ZONE_UTC; } else { tz = TimeZone.getTimeZone("GMT" + tzValue); } Calendar calendar = Calendar.getInstance(tz); calendar.clear(); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, second); return calendar; } else { throw new IllegalArgumentException("Invalid date time: " + time); } }
From source file:org.apache.vysper.xmpp.datetime.DateTimeProfile.java
/** * Parses a date time compliant with ISO-8601 and XEP-0082. * @param time The date time string//from w w w . java 2s .c om * @return A {@link Calendar} representing the date time, in the * time zone specified by the input string * @throws IllegalArgumentException If the input string is not a valid date time * e.g. the time zone is missing */ public Calendar fromDateTime(String time) { Matcher matcher = DATE_TIME_PATTERN.matcher(time); if (matcher.find()) { int year = Integer.valueOf(matcher.group(1)); int month = Integer.valueOf(matcher.group(2)); int day = Integer.valueOf(matcher.group(3)); int hour = Integer.valueOf(matcher.group(4)); int minute = Integer.valueOf(matcher.group(5)); int second = Integer.valueOf(matcher.group(6)); String tzValue = matcher.group(7); TimeZone tz; if (tzValue.equals("Z")) { tz = TIME_ZONE_UTC; } else { tz = TimeZone.getTimeZone("GMT" + tzValue); } Calendar calendar = Calendar.getInstance(tz); calendar.clear(); calendar.set(year, month - 1, day, hour, minute, second); return calendar; } else { throw new IllegalArgumentException("Invalid date time: " + time); } }
From source file:org.apache.vysper.xmpp.datetime.DateTimeProfile.java
/** * Parses a date, compliant with ISO-8601 and XEP-0082. * @param time The date string//from ww w . j a va2 s .co m * @return A {@link Calendar} representing the date * @throws IllegalArgumentException If the input string is not a valid date */ public Calendar fromDate(String time) { Matcher matcher = DATE_PATTERN.matcher(time); if (matcher.find()) { int year = Integer.valueOf(matcher.group(1)); int month = Integer.valueOf(matcher.group(2)); int day = Integer.valueOf(matcher.group(3)); Calendar calendar = Calendar.getInstance(TIME_ZONE_UTC); calendar.clear(); calendar.set(year, month - 1, day); return calendar; } else { throw new IllegalArgumentException("Invalid date time: " + time); } }
From source file:org.apache.olingo.fit.proxy.EntityRetrieveTestITCase.java
@Test public void navigate() { final Order order = getContainer().getOrders().getByKey(8).load(); assertEquals(8, order.getOrderID(), 0); final Timestamp date = order.getOrderDate(); assertNotNull(date);//from w w w .j a v a 2s.c o m final Calendar actual = Calendar.getInstance(TimeZone.getTimeZone("GMT")); actual.clear(); actual.set(2011, 2, 4, 16, 3, 57); assertEquals(actual.getTimeInMillis(), date.getTime()); final Customer customer = getContainer().getCustomers().getByKey(1).load(); assertNotNull(customer); assertEquals(1, customer.getPersonID(), 0); final Address address = customer.getHomeAddress(); assertNotNull(address); assertEquals("98052", address.getPostalCode()); }
From source file:com.swcguild.dvdlibrarymvc.model.Dvd.java
public void setReleaseDate(Date releaseDate) throws ParseException { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // Date date = releaseDate; // int dd = date.getDate() + 1; // int mm = date.getMonth() + 1; // int yyyy = date.getYear(); // if (dd < 10) { // dd = '0' + dd; // };/* w ww.j av a2 s. c o m*/ // if (mm < 10) { // mm = '0' + mm; // }; // String stringDate = (yyyy+"-"+mm+"-"+dd); // releaseDate = df.parse(stringDate); Calendar cal = Calendar.getInstance(); cal.clear(); cal.setTime(releaseDate); int dd = cal.get(Calendar.DATE); int mm = (cal.get(Calendar.MONTH) + 1); int yyyy = cal.get(Calendar.YEAR); if (dd < 10) { dd = 0 + dd; } ; if (mm < 10) { mm = 0 + mm; } ; String stringDate = (yyyy + "-" + (mm) + "-" + (dd)); releaseDate = df.parse(stringDate); this.releaseDate = releaseDate; }