List of usage examples for java.util Calendar MINUTE
int MINUTE
To view the source code for java.util Calendar MINUTE.
Click Source Link
get
and set
indicating the minute within the hour. From source file:it.generatore.DateRandomGaussianGeneratorTest.java
@Test public void testGet() throws Exception { int i = 0;// www. j a v a2 s. c o m int inFascia = 0; int fuoriFascia = 0; Calendar cal = GregorianCalendar.getInstance(); cal.setTimeInMillis(dateRandomGaussianGenerator.minDate); cal = DateUtils.truncate(cal, Calendar.DATE); System.out.println(sdf.format(cal.getTime())); Map<String, Integer> distribuzione = new HashMap<>(); while (++i <= 24 * 60) { cal.add(Calendar.MINUTE, 1); distribuzione.put(getHourKey(cal), 0); } System.out.println(distribuzione.keySet()); i = 0; while (++i <= NUMERO_RECORD) { String strDate = dateRandomGaussianGenerator.get(); //System.out.println("strDate:" + strDate); Matcher m = pattern.matcher(strDate); assertTrue(m.find()); strDate = m.group(1); // System.out.println("strDate:" + strDate); Date date = sdf.parse(strDate); cal.setTime(date); String hourKey = getHourKey(cal); Integer actualValue = distribuzione.get(hourKey); distribuzione.remove(hourKey); distribuzione.put(hourKey, actualValue + 1); if (cal.get(Calendar.HOUR_OF_DAY) >= 9 && cal.get(Calendar.HOUR_OF_DAY) <= 18) { inFascia++; } else { fuoriFascia++; } //System.out.println(strDate); } System.out.println("**** terminato. In fascia: " + inFascia + " fuoriFascia: " + fuoriFascia + " % in fascia: " + (inFascia / NUMERO_RECORD)); assertTrue(inFascia / NUMERO_RECORD >= 0.7d); assertTrue(fuoriFascia / NUMERO_RECORD <= 0.3d); assertTrue(inFascia + fuoriFascia == NUMERO_RECORD); }
From source file:Main.java
public static Date getDateTimeFrom(Date iDate, int mode, int adddate) { Calendar calendar = Calendar.getInstance(); Calendar calendarDate = Calendar.getInstance(); calendarDate.setTime(iDate);//from w w w .ja v a2s . c om calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); switch (mode) { case Calendar.DAY_OF_MONTH: { calendar.set(Calendar.DAY_OF_MONTH, calendarDate.get(Calendar.DAY_OF_MONTH) + adddate); } break; } Date ret = calendar.getTime(); Log.v("!!!!!!!!!! calendar=", "" + ret); return ret; }
From source file:com.spoiledmilk.cykelsuperstier.break_rote.MetroData.java
public static ArrayList<ITransportationInfo> getNext3Arrivals(String line, String startStation, String endStation, Context context) { ArrayList<ITransportationInfo> ret = new ArrayList<ITransportationInfo>(); String bufferString = Util.stringFromJsonAssets(context, "stations/" + filename); JsonNode actualObj = Util.stringToJsonNode(bufferString); JsonNode lines = actualObj.get("lines"); for (int i = 0; i < lines.size(); i++) { JsonNode lineJson = lines.get(i); if (lineJson.get("name").asText().contains(line)) { Calendar calendar = Calendar.getInstance(); int day = calendar.get(Calendar.DAY_OF_WEEK); if (day == 1) day = 6;//from ww w . jav a2s . co m else day -= 2; int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int period = 0, endTime = 0; // startTime try { if ((day == 4 || day == 5) && hour >= 0 && hour <= 7) { // Friday and Saturday night period = lineJson.get("timetable").get("friday_saturday_night").get(0).get("period") .asInt(); endTime = lineJson.get("timetable").get("friday_saturday_night").get(0).get("end_time") .asInt(); } else if ((day < 4 || day == 6) && hour >= 0 && hour <= 5) { // other days at night JsonNode timetableNode = lineJson.get("timetable"); JsonNode timetableNodeContainer = timetableNode.get("sunday_thursday_night"); period = timetableNodeContainer.get(0).get("period").asInt(); endTime = timetableNodeContainer.get(0).get("end_time").asInt(); } else { JsonNode nodeRushour = lineJson.get("timetable").get("weekdays_rushour"); JsonNode nodeOutsideRushour = lineJson.get("timetable").get("weekdays_outside_rushour"); if ((day >= 0 && day < 5) && hour >= nodeRushour.get(0).get("start_time").asInt() && hour < nodeRushour.get(0).get("end_time").asInt()) { endTime = nodeRushour.get(0).get("end_time").asInt(); period = nodeRushour.get(0).get("period").asInt(); } else if ((day >= 0 && day < 5) && hour >= nodeRushour.get(1).get("start_time").asInt() && hour < nodeRushour.get(1).get("end_time").asInt()) { endTime = nodeRushour.get(1).get("end_time").asInt(); period = nodeRushour.get(1).get("period").asInt(); } else if (hour >= nodeOutsideRushour.get(0).get("start_time").asInt() && hour < nodeOutsideRushour.get(0).get("end_time").asInt()) { endTime = nodeOutsideRushour.get(0).get("end_time").asInt(); period = nodeOutsideRushour.get(0).get("period").asInt(); } else { endTime = nodeOutsideRushour.get(1).get("end_time").asInt(); period = nodeOutsideRushour.get(1).get("period").asInt(); } } int currentHour = hour; int currentMinute = minute; int count = 0; period *= getTimeBetweenStations(line, startStation, endStation, context); while (count < 3) { for (int k = 0; k < 60 && count < 3; k += period % 60) { if (k >= currentMinute) { currentMinute = k % 60; currentHour += period / 60; String arrivalTime = (currentHour < 10 ? "0" + currentHour : "" + currentHour) + ":" + (currentMinute < 10 ? "0" + currentMinute : "" + currentMinute); int destHour = currentHour + period / 60; int destMinute = currentMinute + period % 60; if (destMinute > 59) { destHour += destMinute / 60; destMinute = destMinute % 60; } String destTime = (destHour < 10 ? "0" + destHour : "" + destHour) + ":" + (destMinute < 10 ? "0" + destMinute : "" + destMinute); ret.add(new MetroData(arrivalTime, destTime, period)); count++; } } currentMinute = 0; if ((++currentHour) >= endTime) break; } } catch (Exception e) { LOG.e(e.getLocalizedMessage()); } break; } } return ret; }
From source file:ch.cyberduck.core.ftp.parser.StingrayFTPEntryParserTest.java
/** * http://trac.cyberduck.ch/ticket/1198/*from ww w.ja va 2 s.c o m*/ */ @Test public void testFile() { FTPFile parsed; parsed = parser.parseFTPEntry("-r--r--r-- 0 165100 165100 Aug 1 10:24 grau2.tif"); assertNotNull(parsed); assertEquals("grau2.tif", parsed.getName()); assertEquals(FTPFile.FILE_TYPE, parsed.getType()); assertEquals(Calendar.AUGUST, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(1, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertEquals(10, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY)); assertEquals(24, parsed.getTimestamp().get(Calendar.MINUTE)); assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION)); assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)); assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION)); }
From source file:be.boyenvaesen.Humidity.HumidityControllerTest.java
@Before public void setUp() { Random r = new Random(); service.deleteAll();//from w ww . j a v a2 s . c o m firstDate = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(firstDate); cal.add(Calendar.MINUTE, 10); // add 10 minutes secondDate = cal.getTime(); service.addNew(Arrays.asList(new postObject<>(75.1f, firstDate), new postObject<>(80f, secondDate))); // for(int i=0;i<200;i++){ // cal.add(Calendar.MINUTE, r.nextInt(10)); // service.addNew(new postObject<>((float)r.nextInt(100),cal.getTime())); // } }
From source file:net.seratch.taskun.util.CalendarUtil.java
public static Calendar getCalendar(int yyyy, int mm, int dd) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, yyyy);/* www . j a v a 2s . c o m*/ cal.set(Calendar.MONTH, mm - 1); cal.set(Calendar.DATE, dd); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal; }
From source file:com.taurus.compratae.test.ArchivoDbServiceTestCase.java
public void testBuscarTodo() { log.debug("Inicio testRecarga"); setup();/*ww w. j a v a 2s . com*/ Date fecha1 = new Date(); SimpleDateFormat formatoDelTexto = new SimpleDateFormat("yyyy-MM-dd"); String fecha = formatoDelTexto.format(fecha1); Date fechaEnviar = null; try { fechaEnviar = formatoDelTexto.parse(fecha); } catch (ParseException ex) { ex.printStackTrace(); } Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(fechaEnviar.getTime()); cal.add(Calendar.MINUTE, 1439); Date fecha2 = new java.sql.Date(cal.getTimeInMillis()); Archivo archivo = archivoDbService.buscarEntreFechas(fechaEnviar, fecha2); log.debug("Fin testRecarga"); }
From source file:pzalejko.iot.hardware.home.core.task.ShutDownTask.java
@Override public void run() { LOG.debug(LogMessages.SHUT_DOWN_DELAY_VALUE, shutDownDelay); final Calendar c = Calendar.getInstance(); final Date dateNow = new Date(); c.setTime(dateNow);/*from w ww.j ava 2 s.c o m*/ c.add(Calendar.MINUTE, shutDownDelay); LOG.debug(LogMessages.STARTED_SHUT_DOWN_TASK, c.getTime()); try { Thread.sleep(c.getTime().getTime() - dateNow.getTime()); } catch (final InterruptedException e) { LOG.error(LogMessages.ERROR_HAS_OCCURRED, e.getMessage(), e); } }
From source file:net.chrisrichardson.polyglotpersistence.restaurantmanagement.domain.TimeRange.java
public boolean isOpenAtThisTime(Date date) { Calendar c = Calendar.getInstance(); c.setTime(date);//from ww w .j av a2 s .co m int day = c.get(Calendar.DAY_OF_WEEK); int timeOfDay = c.get(Calendar.HOUR_OF_DAY) * 100 + c.get(Calendar.MINUTE); return day == getDayOfWeek() && openingTime <= timeOfDay && timeOfDay <= closingTime; }
From source file:CalendarDemo.java
public void format() { // Tell the calendar what date/time to format calendar.setTime(timeNow);//from w w w . j av a 2s .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))); }