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:net.duckling.ddl.util.Utility.java
public static String getDateShort(Date date) { Calendar calToday = Calendar.getInstance(); calToday.set(Calendar.HOUR_OF_DAY, 0); Calendar calYear = Calendar.getInstance(); calYear.set(Calendar.DAY_OF_YEAR, 1); Calendar cal = Calendar.getInstance(); cal.setTime(date);/*from w ww . j av a 2 s . c o m*/ if (cal.after(calToday)) { return (new SimpleDateFormat("HH:mm")).format(cal.getTime()); } else if (cal.after(calYear)) { return (new SimpleDateFormat("MMdd")).format(cal.getTime()); } else { return (new SimpleDateFormat("yyyy")).format(cal.getTime()); } }
From source file:net.audumla.irrigation.EToCalculator.java
public double calculateETo(Date now) { // refresh if we are in a different day or an elapse time has passed if (!DateUtils.isSameDay(lastCalculated, now) || (DateUtils.getFragmentInMinutes(lastCalculated, Calendar.DAY_OF_YEAR) - DateUtils.getFragmentInMinutes(now, Calendar.DAY_OF_YEAR)) > minuteTimeout) { double debt = 0.0; for (int i = 0; i < calculationDurationInDays; ++i) { try { // add up all the ETo values over the past days. // the current day may use forecast information ClimateData data = zone.getClimateObserver().getClimateData(now); try { double eto = data.getEvapotranspiration(); debt += eto;//from w w w . j a v a 2 s. c om } catch (UnsupportedOperationException ex) { // no ETo information available } try { double rain = data.getRainfall(); // if the rainfall value is a forecast then we revert to the latest observation and use the value // that is the rainfall since 9am. if (!data.getDataSource().getType() .equals(ClimateDataSource.ClimateDataSourceType.DAILY_FORECAST)) { debt -= rain; } else { debt -= data.getObservation(now, ClimateData.ObservationMatch.CLOSEST).getRainfall(); } } catch (UnsupportedOperationException ex) { // no rain information available } // add all the irrigation events for this day against the water debt List<Event> events = zone.getIrrigationEventsForDay(now); for (Event e : events) { if (e.getEventStartTime().before(now)) { debt -= IrrigationZone.calculateIrrigatedDepth(zone, e.getEventDuration()); } } } catch (UnsupportedOperationException ex) { logger.warn("Unable to obtain climate data for " + Time.dateFormatter.format(now), ex); } finally { now = DateUtils.addDays(now, -1); } } currentETo = debt; lastCalculated = now; } return currentETo; }
From source file:CalendarDemo.java
public void format() { // Tell the calendar what date/time to format calendar.setTime(timeNow);//from w w w .j a v a 2 s . c o m // print out most of the known fields System.out.println("ERA: " + calendar.get(Calendar.ERA)); System.out.println("YEAR: " + calendar.get(Calendar.YEAR)); System.out.println("MONTH: " + calendar.get(Calendar.MONTH)); System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR)); System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH)); System.out.println("DATE: " + calendar.get(Calendar.DATE)); System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH)); System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR)); System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK)); System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH)); System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM)); System.out.println("HOUR: " + calendar.get(Calendar.HOUR)); System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY)); System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE)); System.out.println("SECOND: " + calendar.get(Calendar.SECOND)); System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND)); System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000))); System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000))); }
From source file:se.ivankrizsan.messagecowboy.services.taskexecutionstatus.TaskExecutionStatusServiceImpl.java
@Override public synchronized void deleteIfOlderThanDays(final int inMaxAgeInDays) { final Calendar theCalendar = Calendar.getInstance(); theCalendar.add(Calendar.DAY_OF_YEAR, -inMaxAgeInDays); LOGGER.debug("Deleting task execution status entries from earlier than {}", theCalendar.getTime()); mTaskExecutionStatusRepository.deleteOlderThan(theCalendar.getTime()); mTaskExecutionStatusRepository.flush(); }
From source file:parlare.application.server.controller.ControllerFunctions.java
public static String listCookies(String method, String listCookies) throws IOException { String printHTML = ""; switch (method) { case "javascript": printHTML += "<script>"; printHTML += "function setCookie(name,value,days) { "; printHTML += "var expires = \"\"; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = \"; expires=\" + date.toGMTString(); } "; printHTML += "document.cookie = name + \"=\" + value + expires + \"; path=/\";"; printHTML += "} "; printHTML += "function getCookie(name) { var nameEQ = name + \"=\"; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; "; printHTML += "while (c.charAt(0) === ' ') { c = c.substring(1, c.length); } if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length, c.length); } } return null; } "; printHTML += "function eraseCookie(name) { setCookie(name, \"\", -1); } "; printHTML += "</script>"; if (listCookies != null) { String[] tokens = listCookies.split(";"); printHTML += "<script>"; for (String token : tokens) { String[] data = token.trim().split("="); if (data.length == 2) { printHTML += " setCookie('" + data[0] + "', '" + data[1] + "', 60);"; }//from w ww . ja v a2s.c om } printHTML += "</script>"; } break; case "java": DefaultHttpClient httpClient = new DefaultHttpClient(); CookieStore cookieStore = httpClient.getCookieStore(); BasicClientCookie cookie = new BasicClientCookie("HelpMeUniverse", "I need your help my dear universe"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_YEAR, 100); cookie.setExpiryDate(calendar.getTime()); cookie.setDomain("localhost"); cookie.setPath("/"); cookieStore.addCookie(cookie); httpClient.setCookieStore(cookieStore); // Prepare a request object HttpGet httpGet = new HttpGet("http://localhost/"); // Execute the request HttpResponse httpResponse = httpClient.execute(httpGet); // Examine the response status System.out.println("Http request response is: " + httpResponse.getStatusLine()); break; } return printHTML; }
From source file:net.audumla.climate.bom.ObserverTest.java
@Test public void testObservations() { Calendar c = GregorianCalendar.getInstance(); c.setTime(new Date()); c.set(Calendar.MILLISECOND, 0); c.set(Calendar.SECOND, 0);//from w ww. j av a2s . co m c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.DAY_OF_YEAR, c.get(Calendar.DAY_OF_YEAR) - 1); Date now = c.getTime(); BOMClimateDataSource source = ClimateDataSourceFactory.newInstance(BOMClimateDataSource.class); source.setId("086068"); ClimateObserver forcaster = new BOMPeriodicClimateObserver(source); ClimateData data = forcaster.getClimateData(now); Assert.assertEquals(now, data.getTime()); // Assert.assertNotNull(data.getMinimumTemperature()); c.set(Calendar.HOUR_OF_DAY, 12); Date obTime1 = c.getTime(); ClimateObservation obs1 = data.getObservation(obTime1, ClimateData.ObservationMatch.CLOSEST); Assert.assertNotNull(obs1); Assert.assertNotNull(obs1.getTemperature()); c.set(Calendar.HOUR_OF_DAY, 11); Date obTime2 = c.getTime(); ClimateObservation obs2 = data.getObservation(obTime2, ClimateData.ObservationMatch.CLOSEST); Assert.assertNotNull(obs2); Assert.assertNotNull(obs2.getTemperature()); Assert.assertNotSame(obs1.getTime(), obs2.getTime()); }
From source file:com.adaptris.core.fs.NewerThanTest.java
@Test public void testAbsolute() throws Exception { // Make it 2 days ago. Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_YEAR, -2); NewerThan filter = new NewerThan("" + c.getTime().getTime()); File file = writeFile(TempFileUtils.createTrackedFile(filter)); assertTrue(filter.accept(file));//ww w. ja v a 2s .c o m }
From source file:com.netflix.genie.core.util.UnixProcessCheckerUnitTests.java
/** * Setup for the tests.//from w ww .j av a 2 s . c o m */ @Before public void setup() { Assume.assumeTrue(SystemUtils.IS_OS_UNIX); this.executor = Mockito.mock(Executor.class); final Calendar tomorrow = Calendar.getInstance(); // For standard tests this will keep it from dying tomorrow.add(Calendar.DAY_OF_YEAR, 1); this.processChecker = new UnixProcessChecker(PID, this.executor, tomorrow.getTime()); }
From source file:com.streamreduce.util.CAGenerator.java
public static X509Certificate generateCACert(KeyPair keyPair) throws Exception { Date startDate = new Date(System.currentTimeMillis()); // time from which certificate is valid Calendar expiry = Calendar.getInstance(); expiry.add(Calendar.DAY_OF_YEAR, 1000 * 365); Date expiryDate = expiry.getTime(); // time after which certificate is not valid BigInteger serialNumber = new BigInteger(Long.toString(System.currentTimeMillis())); // serial number for certificate X509V3CertificateGenerator certGen = new X509V3CertificateGenerator(); X500Principal dnName = new X500Principal("CN=Nodeable Client"); certGen.setSerialNumber(serialNumber); certGen.setIssuerDN(dnName);/*from ww w .j a v a 2 s. c o m*/ certGen.setNotBefore(startDate); certGen.setNotAfter(expiryDate); certGen.setSubjectDN(dnName); certGen.setPublicKey(keyPair.getPublic()); certGen.setSignatureAlgorithm("MD5withRSA"); certGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifierStructure(keyPair.getPublic())); certGen.addExtension(X509Extensions.SubjectKeyIdentifier, false, new SubjectKeyIdentifierStructure(keyPair.getPublic())); return certGen.generate(keyPair.getPrivate()); // note: private key of CA }
From source file:net.duckling.ddl.util.Utility.java
public static String getDateCustom(Date date, String fmt) { Calendar calToday = Calendar.getInstance(); calToday.set(Calendar.HOUR_OF_DAY, 0); Calendar calYear = Calendar.getInstance(); calYear.set(Calendar.DAY_OF_YEAR, 1); Calendar cal = Calendar.getInstance(); cal.setTime(date);/* ww w .jav a 2 s.com*/ return (new SimpleDateFormat(fmt)).format(cal.getTime()); }