List of usage examples for java.util Calendar DAY_OF_YEAR
int DAY_OF_YEAR
To view the source code for java.util Calendar DAY_OF_YEAR.
Click Source Link
get
and set
indicating the day number within the current year. From source file:com.glaf.core.util.DateUtils.java
/** * ?/* w ww . java 2 s .com*/ * * @param startDate * @param endDate * @return */ public static int getDaysBetween(Calendar startDate, Calendar endDate) { if (startDate.after(endDate)) { java.util.Calendar swap = startDate; startDate = endDate; endDate = swap; } int days = endDate.get(java.util.Calendar.DAY_OF_YEAR) - startDate.get(java.util.Calendar.DAY_OF_YEAR); int y2 = endDate.get(java.util.Calendar.YEAR); if (startDate.get(java.util.Calendar.YEAR) != y2) { startDate = (java.util.Calendar) startDate.clone(); do { days += startDate.getActualMaximum(java.util.Calendar.DAY_OF_YEAR); startDate.add(java.util.Calendar.YEAR, 1); } while (startDate.get(java.util.Calendar.YEAR) != y2); } return days; }
From source file:com.joefernandez.irrduino.android.remote.ViewReportActivity.java
private boolean isSameDay(Calendar cal1, Calendar cal2) { return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR); }
From source file:edu.ucsb.nceas.ezid.test.EZIDServiceTest.java
/** Generate a timestamp for use in IDs. */ public static String generateTimeString() { StringBuffer guid = new StringBuffer(); // Create a calendar to get the date formatted properly String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); Date trialTime = new Date(); calendar.setTime(trialTime);// w w w . j a v a 2 s. com guid.append(calendar.get(Calendar.YEAR)); guid.append(calendar.get(Calendar.DAY_OF_YEAR)); guid.append(calendar.get(Calendar.HOUR_OF_DAY)); guid.append(calendar.get(Calendar.MINUTE)); guid.append(calendar.get(Calendar.SECOND)); guid.append(calendar.get(Calendar.MILLISECOND)); double random = Math.random(); guid.append(random); return guid.toString(); }
From source file:com.livinglogic.ul4.FunctionFormat.java
public static String call(Date obj, String formatString, Locale locale) { if (locale == null) locale = Locale.ENGLISH;// w ww . j a v a 2s .c om Calendar calendar = new GregorianCalendar(); calendar.setTime((Date) obj); StringBuilder buffer = new StringBuilder(); boolean escapeCharacterFound = false; int formatStringLength = formatString.length(); for (int i = 0; i < formatStringLength; i++) { char c = formatString.charAt(i); if (escapeCharacterFound) { switch (c) { case 'a': buffer.append(new SimpleDateFormat("EE", locale).format(obj)); break; case 'A': buffer.append(new SimpleDateFormat("EEEE", locale).format(obj)); break; case 'b': buffer.append(new SimpleDateFormat("MMM", locale).format(obj)); break; case 'B': buffer.append(new SimpleDateFormat("MMMM", locale).format(obj)); break; case 'c': { String format = cFormats.get(locale.getLanguage()); if (format == null) format = cFormats.get("en"); buffer.append(call(obj, format, locale)); break; } case 'd': buffer.append(twodigits.format(calendar.get(Calendar.DAY_OF_MONTH))); break; case 'f': buffer.append(sixdigits.format(calendar.get(Calendar.MILLISECOND) * 1000)); break; case 'H': buffer.append(twodigits.format(calendar.get(Calendar.HOUR_OF_DAY))); break; case 'I': buffer.append(twodigits.format(((calendar.get(Calendar.HOUR_OF_DAY) - 1) % 12) + 1)); break; case 'j': buffer.append(threedigits.format(calendar.get(Calendar.DAY_OF_YEAR))); break; case 'm': buffer.append(twodigits.format(calendar.get(Calendar.MONTH) + 1)); break; case 'M': buffer.append(twodigits.format(calendar.get(Calendar.MINUTE))); break; case 'p': buffer.append(new SimpleDateFormat("aa", locale).format(obj)); break; case 'S': buffer.append(twodigits.format(calendar.get(Calendar.SECOND))); break; case 'U': buffer.append(twodigits.format(BoundDateMethodWeek.call(obj, 6))); break; case 'w': buffer.append(weekdayFormats.get(calendar.get(Calendar.DAY_OF_WEEK))); break; case 'W': buffer.append(twodigits.format(BoundDateMethodWeek.call(obj, 0))); break; case 'x': { String format = xFormats.get(locale.getLanguage()); if (format == null) format = xFormats.get("en"); buffer.append(call(obj, format, locale)); break; } case 'X': { String format = XFormats.get(locale.getLanguage()); if (format == null) format = XFormats.get("en"); buffer.append(call(obj, format, locale)); break; } case 'y': buffer.append(twodigits.format(calendar.get(Calendar.YEAR) % 100)); break; case 'Y': buffer.append(fourdigits.format(calendar.get(Calendar.YEAR))); break; default: buffer.append(c); break; } escapeCharacterFound = false; } else { if (c == '%') escapeCharacterFound = true; else buffer.append(c); } } if (escapeCharacterFound) buffer.append('%'); return buffer.toString(); }
From source file:Main.java
/** * <p>Returns the number of days within the * fragment. All datefields greater than the fragment will be ignored.</p> * //from w w w .j a va 2 s. com * <p>Asking the days of any date will only return the number of days * of the current month (resulting in a number between 1 and 31). This * method will retrieve the number of days for any fragment. * For example, if you want to calculate the number of days past this year, * your fragment is Calendar.YEAR. The result will be all days of the * past month(s).</p> * * <p>Valid fragments are: Calendar.YEAR, Calendar.MONTH, both * Calendar.DAY_OF_YEAR and Calendar.DATE, Calendar.HOUR_OF_DAY, * Calendar.MINUTE, Calendar.SECOND and Calendar.MILLISECOND * A fragment less than or equal to a DAY field will return 0.</p> * * <p> * <ul> * <li>January 28, 2008 with Calendar.MONTH as fragment will return 28 * (equivalent to calendar.get(Calendar.DAY_OF_MONTH))</li> * <li>February 28, 2008 with Calendar.MONTH as fragment will return 28 * (equivalent to calendar.get(Calendar.DAY_OF_MONTH))</li> * <li>January 28, 2008 with Calendar.YEAR as fragment will return 28 * (equivalent to calendar.get(Calendar.DAY_OF_YEAR))</li> * <li>February 28, 2008 with Calendar.YEAR as fragment will return 59 * (equivalent to calendar.get(Calendar.DAY_OF_YEAR))</li> * <li>January 28, 2008 with Calendar.MILLISECOND as fragment will return 0 * (a millisecond cannot be split in days)</li> * </ul> * </p> * * @param calendar the calendar to work with, not null * @param fragment the Calendar field part of calendar to calculate * @return number of days within the fragment of date * @throws IllegalArgumentException if the date is <code>null</code> or * fragment is not supported * @since 2.4 */ public static long getFragmentInDays(Calendar calendar, int fragment) { return getFragment(calendar, fragment, Calendar.DAY_OF_YEAR); }
From source file:Statement.Statement.java
private void loadRevenue() { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_YEAR, 1); Date tomorrow = calendar.getTime(); dateFormat.format(tomorrow);//from w ww . ja va2s . c o m evaluator = new HighlightEvaluator(); evaluator.setStartDate(tomorrow); try { PreparedStatement st = cnn.prepareStatement("SELECT Date FROM Revenue where ShopID = ?"); st.setString(1, code); ResultSet rs = st.executeQuery(); while (rs.next()) { evaluator.add(rs.getDate(1)); } } catch (Exception e) { } jc.getDayChooser().addDateEvaluator(evaluator); jc.setCalendar(jc.getCalendar()); }
From source file:org.activiti.crystalball.simulator.SimulateBottleneckTest.java
/** * run simulation for 30 days and generate report * /*ww w . j a v a2 s .c o m*/ * @param appContext * @throws Exception */ protected void runSimulation(AbstractApplicationContext appContext, String generatedImage) throws Exception { SimulationRun simRun = (SimulationRun) appContext.getBean(SimulationRun.class); Calendar c = Calendar.getInstance(); c.clear(); c.set(2013, 1, 1); Date startDate = c.getTime(); c.add(Calendar.DAY_OF_YEAR, 30); Date finishDate = c.getTime(); // run simulation for 30 days @SuppressWarnings("unused") List<ResultEntity> resultEventList = simRun.execute(startDate, finishDate); AbstractProcessEngineGraphGenerator generator = (AbstractProcessEngineGraphGenerator) appContext .getBean("reportGenerator"); RepositoryService simRepositoryService = (RepositoryService) appContext.getBean("simRepositoryService"); String processDefinitionId = simRepositoryService.createProcessDefinitionQuery() .processDefinitionKey(PROCESS_KEY).singleResult().getId(); generator.generateReport(processDefinitionId, startDate, finishDate, generatedImage); }
From source file:com.acmeair.wxs.service.CustomerServiceImpl.java
@Override public CustomerSession createSession(String customerId) { try {/* www. ja va 2s . c o m*/ String sessionId = keyGenerator.generate().toString(); Date now = new Date(); Calendar c = Calendar.getInstance(); c.setTime(now); c.add(Calendar.DAY_OF_YEAR, DAYS_TO_ALLOW_SESSION); Date expiration = c.getTime(); CustomerSession cSession = new CustomerSession(sessionId, customerId, now, expiration); Session session = sessionManager.getObjectGridSession(); ObjectMap customerSessionMap = session.getMap(CUSTOMER_SESSION_MAP_NAME); customerSessionMap.insert(cSession.getId(), cSession); return cSession; } catch (Exception e) { throw new RuntimeException(e); } }
From source file:io.apiman.manager.api.core.metrics.AbstractMetricsAccessor.java
/** * Generate the histogram buckets based on the time frame requested and the interval. This will * add an entry for each 'slot' or 'bucket' in the histogram, setting the count to 0. * @param rval//ww w.j ava 2 s . c o m * @param from * @param to * @param interval */ public static <T extends HistogramDataPoint, K> Map<K, T> generateHistogramSkeleton(HistogramBean<T> rval, DateTime from, DateTime to, HistogramIntervalType interval, Class<T> dataType, Class<K> keyType) { Map<K, T> index = new HashMap<>(); Calendar fromCal = from.toGregorianCalendar(); Calendar toCal = to.toGregorianCalendar(); switch (interval) { case day: fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case hour: fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case minute: fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case month: fromCal.set(Calendar.DAY_OF_MONTH, 1); fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; case week: fromCal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); fromCal.set(Calendar.HOUR_OF_DAY, 0); fromCal.set(Calendar.MINUTE, 0); fromCal.set(Calendar.SECOND, 0); fromCal.set(Calendar.MILLISECOND, 0); break; default: break; } while (fromCal.before(toCal)) { String label = formatDateWithMillis(fromCal); T point; try { point = dataType.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } point.setLabel(label); rval.addDataPoint(point); if (keyType == String.class) { index.put((K) label, point); } else { index.put((K) new Long(fromCal.getTimeInMillis()), point); } switch (interval) { case day: fromCal.add(Calendar.DAY_OF_YEAR, 1); break; case hour: fromCal.add(Calendar.HOUR_OF_DAY, 1); break; case minute: fromCal.add(Calendar.MINUTE, 1); break; case month: fromCal.add(Calendar.MONTH, 1); break; case week: fromCal.add(Calendar.WEEK_OF_YEAR, 1); break; default: break; } } return index; }
From source file:org.andicar.service.UpdateCheckService.java
private void setNextRun() { Calendar cal = Calendar.getInstance(); if (cal.get(Calendar.HOUR_OF_DAY) >= 18) cal.add(Calendar.DAY_OF_YEAR, 1); cal.set(Calendar.HOUR_OF_DAY, 20); cal.set(Calendar.MINUTE, 0);/*www .ja v a2s . c o m*/ Intent i = new Intent(this, UpdateCheckService.class); PendingIntent pIntent = PendingIntent.getService(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC, cal.getTimeInMillis(), pIntent); }