List of usage examples for java.util Calendar DAY_OF_MONTH
int DAY_OF_MONTH
To view the source code for java.util Calendar DAY_OF_MONTH.
Click Source Link
get
and set
indicating the day of the month. From source file:net.servicefixture.converter.XMLGregorianCalendarConverter.java
private XMLGregorianCalendar calendarToXMLGregorianCalendar(Calendar calendar) { XMLGregorianCalendar xmlCal;// ww w . j a v a2s .co m try { xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(); } catch (DatatypeConfigurationException e) { throw new RuntimeException("Failed to create XMLGregorianCalendar", e); } xmlCal.setYear(calendar.get(Calendar.YEAR)); xmlCal.setMonth(calendar.get(Calendar.MONTH) + 1); xmlCal.setDay(calendar.get(Calendar.DAY_OF_MONTH)); xmlCal.setHour(calendar.get(Calendar.HOUR)); xmlCal.setMinute(calendar.get(Calendar.MINUTE)); xmlCal.setSecond(calendar.get(Calendar.SECOND)); xmlCal.setMillisecond(calendar.get(Calendar.MILLISECOND)); return xmlCal; }
From source file:Main.java
/** * * This method is a utility method to create a new java.sql.Date in one line. * * @param year/*from w w w .j av a 2 s . c om*/ * @param month * @param day * @param hour * @param minute * @param second * * @return a populated java.sql.Date with the year, month, hour, minute, and second populated, with no value for millisecond. * */ public static java.sql.Date newDate(Integer year, Integer month, Integer day, Integer hour, Integer minute, Integer second) { // test for null arguments if (year == null) { throw new IllegalArgumentException("Argument 'year' passed in was null."); } if (month == null) { throw new IllegalArgumentException("Argument 'month' passed in was null."); } if (day == null) { throw new IllegalArgumentException("Argument 'day' passed in was null."); } if (hour == null) { throw new IllegalArgumentException("Argument 'hour' passed in was null."); } if (minute == null) { throw new IllegalArgumentException("Argument 'minute' passed in was null."); } if (second == null) { throw new IllegalArgumentException("Argument 'second' passed in was null."); } Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, second); calendar.clear(Calendar.MILLISECOND); return new java.sql.Date(calendar.getTimeInMillis()); }
From source file:com.blackberry.logdriver.timestamp.Rfc3164TimestampParser.java
@Override public long parseTimestatmp(String timestamp) throws ParseException { if (timestamp == null) { throw new ParseException("Timestamp is null", 0); }/*from www . j av a 2s .c o m*/ // Before we parse the date, add the current year to the string. That way, // we get a correct timestamp. If I try to add the year after, we run into // issues with leap years. Calendar currentCalendar = Calendar.getInstance(); int currentYear = currentCalendar.get(Calendar.YEAR); Date date = dateFormat.parse(currentYear + " " + timestamp); Calendar logCalendar = Calendar.getInstance(); logCalendar.setTime(date); // If today is the first of January, and the log is for the 31st of // December, then we probably just used the wrong year. So lets roll the // year back by one in that case. if (logCalendar.get(Calendar.DAY_OF_MONTH) == 31 && logCalendar.get(Calendar.MONTH) == Calendar.DECEMBER && currentCalendar.get(Calendar.DAY_OF_MONTH) == 1 && currentCalendar.get(Calendar.MONTH) == Calendar.JANUARY) { logCalendar.add(Calendar.YEAR, -1); // Contrariwise, a bad clock can give us Jan 1 logs on December 31 } else if (currentCalendar.get(Calendar.DAY_OF_MONTH) == 31 && currentCalendar.get(Calendar.MONTH) == Calendar.DECEMBER && logCalendar.get(Calendar.DAY_OF_MONTH) == 1 && logCalendar.get(Calendar.MONTH) == Calendar.JANUARY) { logCalendar.add(Calendar.YEAR, 1); } return logCalendar.getTimeInMillis(); }
From source file:eionet.gdem.qa.WQCleanerJobTest.java
@Test public void testCanDelete() throws Exception { Properties.wqJobMaxAge = 24;// 24 hours WorkqueueJob job = new WorkqueueJob(); job.setStatus(Constants.XQ_PROCESSING); Calendar jobDate = Calendar.getInstance(); jobDate.add(Calendar.DAY_OF_MONTH, -1); job.setJobTimestamp(jobDate.getTime()); assertFalse(WQCleanerJob.canDeleteJob(job)); jobDate.add(Calendar.DAY_OF_MONTH, -2); job.setJobTimestamp(jobDate.getTime()); assertFalse(WQCleanerJob.canDeleteJob(job)); job.setStatus(Constants.XQ_RECEIVED); assertFalse(WQCleanerJob.canDeleteJob(job)); job.setStatus(Constants.XQ_PROCESSING); assertFalse(WQCleanerJob.canDeleteJob(job)); job.setStatus(Constants.XQ_READY);//from w ww . j a v a 2s . c o m assertTrue(WQCleanerJob.canDeleteJob(job)); job.setStatus(Constants.XQ_FATAL_ERR); assertTrue(WQCleanerJob.canDeleteJob(job)); job.setStatus(Constants.XQ_LIGHT_ERR); assertTrue(WQCleanerJob.canDeleteJob(job)); }
From source file:com.polyvi.xface.extension.calendar.XCalendarExt.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { Calendar calendar = Calendar.getInstance(); mCallbackContext = callbackContext;/* w ww . j a va 2 s . c o m*/ if (COMMAND_GET_TIME.equals(action)) { // ??? int hours = calendar.get(Calendar.HOUR_OF_DAY); int minutes = calendar.get(Calendar.MINUTE); if (2 == args.length()) { hours = args.getInt(0); minutes = args.getInt(1); } getTime(hours, minutes); } else if (COMMAND_GET_DATE.equals(action)) { // ??? int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); if (3 == args.length()) { year = args.getInt(0); month = args.getInt(1); day = args.getInt(2); } getDate(year, month, day); } PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); result.setKeepCallback(true); callbackContext.sendPluginResult(result); return true; }
From source file:net.firejack.platform.core.utils.DateUtils.java
/** * Increments the date by one day/*w w w . j a v a 2s . com*/ * @param date - date to be incremented */ public static void incDateByDay(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.DAY_OF_MONTH, 1); date.setTime(cal.getTimeInMillis()); }
From source file:org.sample.validation.MyBean.java
@Future public Date showDate(boolean correct) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_MONTH, correct ? 5 : -5); return cal.getTime(); }
From source file:adalid.commons.util.TimeUtils.java
public static synchronized Time currentTime() { calendar.setTimeInMillis(currentTimeMillis()); calendar.set(Calendar.YEAR, 1970); calendar.set(Calendar.MONTH, Calendar.JANUARY); calendar.set(Calendar.DAY_OF_MONTH, 1); return new Time(calendar.getTimeInMillis()); }
From source file:com.haulmont.cuba.core.sys.querymacro.TimeTodayQueryMacroHandler.java
@Override protected String doExpand(String macro) { count++;// ww w . j a v a2 s.co m String[] args = macro.split(","); if (args.length != 1 && args.length != 2) throw new RuntimeException("Invalid macro: " + macro); String field = args[0].trim(); String param1 = field.replace(".", "_") + "_" + count + "_1"; String param2 = field.replace(".", "_") + "_" + count + "_2"; TimeZone timeZone = getTimeZoneFromArgs(args, 1); if (timeZone == null) { timeZone = TimeZone.getDefault(); } Calendar cal = Calendar.getInstance(timeZone); cal.setTime(AppBeans.get(TimeSource.class).currentTimestamp()); params.put(param1, DateUtils.truncate(cal, Calendar.DAY_OF_MONTH).getTime()); cal.add(Calendar.DAY_OF_MONTH, 1); params.put(param2, DateUtils.truncate(cal, Calendar.DAY_OF_MONTH).getTime()); return String.format("(%s >= :%s and %s < :%s)", field, param1, field, param2); }
From source file:com.prowidesoftware.swift.model.field.Field11RTest.java
@Test public void testParser() { Field11R f = new Field11R((String) null); assertNull(f.getComponent1());// w w w . j a va2 s .c o m assertNull(f.getComponent2()); assertNull(f.getComponent3()); assertNull(f.getComponent4()); f = new Field11R("100"); assertEquals("100", f.getComponent1()); assertEquals("100", f.getMT()); assertNull(f.getComponent2()); assertNull(f.getComponent3()); assertNull(f.getComponent4()); f = new Field11R("100\n091019"); assertEquals("100", f.getComponent1()); assertEquals("100", f.getMT()); assertEquals("091019", f.getComponent2()); assertEquals(2009, f.getComponent2AsCalendar().get(Calendar.YEAR)); assertEquals(10, f.getComponent2AsCalendar().get(Calendar.MONTH) + 1); //MONTH is zero based at Calendar assertEquals(19, f.getComponent2AsCalendar().get(Calendar.DAY_OF_MONTH)); assertNull(f.getComponent3()); assertNull(f.getComponent4()); f = new Field11R("100\n091019\nabc"); assertEquals("100", f.getComponent1()); assertEquals("100", f.getMT()); assertEquals("091019", f.getComponent2()); assertEquals(2009, f.getComponent2AsCalendar().get(Calendar.YEAR)); assertEquals(10, f.getComponent2AsCalendar().get(Calendar.MONTH) + 1); assertEquals(19, f.getComponent2AsCalendar().get(Calendar.DAY_OF_MONTH)); assertEquals("abc", f.getComponent3()); assertNull(f.getComponent4()); f = new Field11R("100\n091019\n1234567890"); assertEquals("1234", f.getComponent3()); assertEquals("567890", f.getComponent4()); }