List of usage examples for java.util Calendar HOUR_OF_DAY
int HOUR_OF_DAY
To view the source code for java.util Calendar HOUR_OF_DAY.
Click Source Link
get
and set
indicating the hour of the day. From source file:frk.gpssimulator.service.impl.DefaultGpsdService.java
@Override public void updatePosition(PositionInfo position) { // an NMEA RMC position sentence (report) is of form: // $GPRMC,124426,A,5920.7019,N,02803.2893,E,,,121212,, Calendar cal = Calendar.getInstance(); Integer hour = cal.get(Calendar.HOUR_OF_DAY); Integer minute = cal.get(Calendar.MINUTE); Integer second = cal.get(Calendar.SECOND); Integer date = cal.get(Calendar.DATE); Integer month = cal.get(Calendar.MONTH) + 1; // java Calendar month // starts at 0 Integer year = cal.get(Calendar.YEAR) % 100; // convert to 2 digit year String sHour = String.format("%02d", hour); String sMinute = String.format("%02d", minute); String sSecond = String.format("%02d", second); String sDate = String.format("%02d", date); String sMonth = String.format("%02d", month); String sYear = String.format("%02d", year); String sentence = null;/* w ww . ja v a 2 s . c o m*/ if (position == null) { sentence = "$GPRMC," + sHour + sMinute + sSecond + ",A,,,,,,," + sDate + sMonth + sYear + ",,"; } else { double lat = position.getPosition().getLatitude(); double lon = position.getPosition().getLongitude(); String latSuffix = "N"; if (lat < 0) { latSuffix = "S"; } lat = Math.abs(lat); String lonSuffix = "E"; if (lon < 0) { lonSuffix = "W"; } lon = Math.abs(lon); long latDeg = (long) lat; // degree part double latMin = (lat - latDeg) * 60; // minute part long latMinWhole = (long) latMin; // whole part of minute Double latMinFrac = latMin - latMinWhole; // fractional part of // minute String sLatDeg = String.format("%02d", latDeg); String sLatMinWhole = String.format("%02d", latMinWhole); String sLatMinFrac = latMinFrac.toString().replace("0.", "."); long lonDeg = (long) lon; // degree part double lonMin = (lon - lonDeg) * 60; // minute part long lonMinWhole = (long) lonMin; // whole part of minute Double lonMinFrac = lonMin - lonMinWhole; // fractional part of // minute String sLonDeg = String.format("%02d", lonDeg); String sLonMinWhole = String.format("%02d", lonMinWhole); String sLonMinFrac = lonMinFrac.toString().replace("0.", "."); sentence = "$GPRMC," + sHour + sMinute + sSecond + ",A," + sLatDeg + sLatMinWhole + sLatMinFrac + "," + latSuffix + "," + sLonDeg + sLonMinWhole + sLonMinFrac + "," + lonSuffix + ",,," + sDate + sMonth + sYear + ",,"; } try { pipeWriter.write(sentence + "\r\n"); pipeWriter.flush(); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:DateUtils.java
/** * Get unix style date string.//from w w w . j av a 2 s. co m */ public final static String getUnixDate(long millis) { if (millis < 0) { return "------------"; } StringBuffer sb = new StringBuffer(16); Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(millis); // month sb.append(MONTHS[cal.get(Calendar.MONTH)]); sb.append(' '); // day int day = cal.get(Calendar.DATE); if (day < 10) { sb.append(' '); } sb.append(day); sb.append(' '); long sixMonth = 15811200000L; // 183L * 24L * 60L * 60L * 1000L; long nowTime = System.currentTimeMillis(); if (Math.abs(nowTime - millis) > sixMonth) { // year int year = cal.get(Calendar.YEAR); sb.append(' '); sb.append(year); } else { // hour int hh = cal.get(Calendar.HOUR_OF_DAY); if (hh < 10) { sb.append('0'); } sb.append(hh); sb.append(':'); // minute int mm = cal.get(Calendar.MINUTE); if (mm < 10) { sb.append('0'); } sb.append(mm); } return sb.toString(); }
From source file:com.qpark.eip.core.spring.statistics.dao.StatisticsLoggingDao.java
/** * Get a {@link Date}, where hours, minutes, seconds and milliseconds are * set to 0.//from w w w. j a v a2 s . c o m * * @return the {@link Date} . */ private static Date getDayEnd(final Date d) { final Calendar gc = new GregorianCalendar(LOGGING_TIMEZONE); gc.setTime(d); gc.set(Calendar.HOUR_OF_DAY, 23); gc.set(Calendar.MINUTE, 59); gc.set(Calendar.SECOND, 59); gc.set(Calendar.MILLISECOND, 0); return gc.getTime(); }
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;//from w ww .j ava 2s . c om 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:com.autentia.common.util.DateFormater.java
public static Date normalizeEndDate(Date date) { GregorianCalendar gCalendar = new GregorianCalendar(); gCalendar.setTime(date);//from w ww . j a va 2 s . com gCalendar.set(Calendar.HOUR_OF_DAY, 23); gCalendar.set(Calendar.MINUTE, 59); gCalendar.set(Calendar.SECOND, 59); gCalendar.set(Calendar.MILLISECOND, 999); return gCalendar.getTime(); }
From source file:com.sirma.itt.emf.time.ISO8601DateFormat.java
/** * Format calendar instance into ISO format. * /* w w w .j a va2s . c o m*/ * @param calendar * the calendar instance to format * @return the ISO formatted string */ public static String format(Calendar calendar) { if (calendar == null) { return null; } StringBuilder formatted = new StringBuilder(28); padInt(formatted, calendar.get(Calendar.YEAR), 4); formatted.append('-'); padInt(formatted, calendar.get(Calendar.MONTH) + 1, 2); formatted.append('-'); padInt(formatted, calendar.get(Calendar.DAY_OF_MONTH), 2); formatted.append('T'); padInt(formatted, calendar.get(Calendar.HOUR_OF_DAY), 2); formatted.append(':'); padInt(formatted, calendar.get(Calendar.MINUTE), 2); formatted.append(':'); padInt(formatted, calendar.get(Calendar.SECOND), 2); formatted.append('.'); padInt(formatted, calendar.get(Calendar.MILLISECOND), 3); TimeZone tz = calendar.getTimeZone(); int offset = tz.getOffset(calendar.getTimeInMillis()); formatted.append(getTimeZonePadding(offset)); return formatted.toString(); }
From source file:org.openmrs.module.rwandaprimarycare.AllEncountersController.java
@RequestMapping("/module/rwandaprimarycare/allEncounters") public String listAllEncounters(@RequestParam("patientId") int patientId, ModelMap model) throws PrimaryCareException { //LK: Need to ensure that all primary care methods only throw a PrimaryCareException //So that errors will be directed to a touch screen error page try {//from w w w. j ava 2 s .co m Patient patient = Context.getPatientService().getPatient(patientId); SortedMap<Date, List<Encounter>> encounters = new TreeMap<Date, List<Encounter>>( Collections.reverseOrder()); for (Encounter e : Context.getEncounterService().getEncountersByPatient(patient)) { Calendar cal = Calendar.getInstance(); cal.setTime(e.getEncounterDatetime()); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date day = cal.getTime(); List<Encounter> holder = encounters.get(day); if (holder == null) { holder = new ArrayList<Encounter>(); encounters.put(day, holder); } holder.add(e); } model.addAttribute("patient", patient); model.addAttribute("encounters", encounters); model.addAttribute("vitalsEncounterType", PrimaryCareBusinessLogic.getVitalsEncounterType()); model.addAttribute("registrationEncounterType", PrimaryCareBusinessLogic.getRegistrationEncounterType()); } catch (Exception e) { throw new PrimaryCareException(e); } return "/module/rwandaprimarycare/allEncounters"; }
From source file:com.ar.dev.tierra.api.dao.impl.DetalleTransferenciaDAOimpl.java
@Override public List<DetalleTransferencia> getDaily() { Criteria criteria = getSession().createCriteria(DetalleTransferencia.class); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); Date fromDate = calendar.getTime(); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); Date toDate = calendar.getTime(); criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate)); criteria.addOrder(Order.desc("idDetalleTransferencia")); List<DetalleTransferencia> list = criteria.list(); return list;/*from w w w . j av a2s . c o m*/ }
From source file:DateUtil.java
/** * Returns a Date set to the first possible millisecond of the day, just * after midnight. If a null day is passed in, a new Date is created. * midnight (00m 00h 00s)//from ww w . java2 s .c o m */ public static Date getStartOfDay(Date day, Calendar cal) { if (day == null) day = new Date(); cal.setTime(day); cal.set(Calendar.HOUR_OF_DAY, cal.getMinimum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getMinimum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getMinimum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND)); return cal.getTime(); }
From source file:ch.cyberduck.core.ftp.parser.UnixFTPEntryParserTest.java
@Test public void testParseTimestamp() { FTPFileEntryParser parser = new FTPParserSelector().getParser("UNIX"); FTPFile parsed;/* w w w . j a va2 s . c o m*/ parsed = parser .parseFTPEntry("drw-rw-rw- 1 user ftp 0 DEC 11 20:56 ADMIN_Documentation"); assertNotNull(parsed); assertNotNull(parsed.getTimestamp()); assertEquals(Calendar.DECEMBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(11, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); assertEquals(20, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY)); assertEquals(56, parsed.getTimestamp().get(Calendar.MINUTE)); parsed = parser.parseFTPEntry("drwxr-xr-x 3 ftp ftp 512 Mar 15 2004 doc"); assertNotNull(parsed); assertNotNull(parsed.getTimestamp()); assertEquals(2004, parsed.getTimestamp().get(Calendar.YEAR)); assertEquals(Calendar.MARCH, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(15, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); parsed = parser.parseFTPEntry("drwxrwxr-x 2 ftp ftp 512 Oct 23 2007 aurox"); assertNotNull(parsed); assertNotNull(parsed.getTimestamp()); assertEquals(2007, parsed.getTimestamp().get(Calendar.YEAR)); assertEquals(Calendar.OCTOBER, parsed.getTimestamp().get(Calendar.MONTH)); assertEquals(23, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH)); }