List of usage examples for java.util Date getSeconds
@Deprecated public int getSeconds()
From source file:org.springframework.extensions.webscripts.json.JSONUtils.java
/** * Convert value to JSON string/*w w w .j a v a 2s .c o m*/ * * @param value Java object value * @param writer JSONWriter for output stream * @throws IOException */ private void valueToJSONString(Object value, JSONWriter writer) throws IOException { if (value instanceof IdScriptableObject && TYPE_DATE.equals(((IdScriptableObject) value).getClassName())) { Date date = (Date) Context.jsToJava(value, Date.class); // Build the JSON object to represent the UTC date writer.startObject().writeValue("zone", "UTC").writeValue("year", date.getYear()) .writeValue("month", date.getMonth()).writeValue("date", date.getDate()) .writeValue("hours", date.getHours()).writeValue("minutes", date.getMinutes()) .writeValue("seconds", date.getSeconds()).writeValue("milliseconds", date.getTime()) .endObject(); } else if (value instanceof NativeJavaObject) { // extract the underlying Java object and recursively output Object javaValue = Context.jsToJava(value, Object.class); valueToJSONString(javaValue, writer); } else if (value instanceof NativeArray) { // Output the native object nativeArrayToJSONString((NativeArray) value, writer); } else if (value instanceof NativeObject) { // Output the native array nativeObjectToJSONString((NativeObject) value, writer); } else if (value instanceof Number) { if (value instanceof Integer || value instanceof Long) { writer.writeValue(((Number) value).longValue()); } else if (value instanceof Double) { writer.writeValue(((Number) value).doubleValue()); } else if (value instanceof Float) { writer.writeValue(((Number) value).floatValue()); } else { writer.writeValue(((Number) value).doubleValue()); } } else if (value instanceof Boolean) { writer.writeValue(((Boolean) value).booleanValue()); } else if (value instanceof Map) { writer.startObject(); for (Object key : ((Map) value).keySet()) { writer.startValue(key.toString()); valueToJSONString(((Map) value).get(key), writer); writer.endValue(); } writer.endObject(); } else if (value instanceof List) { writer.startArray(); for (Object val : (List) value) { valueToJSONString(val, writer); } writer.endArray(); } else if (value != null) { writer.writeValue(value.toString()); } else { writer.writeNullValue(); } }
From source file:org.openmrs.module.kenyaemr.fragment.controller.NextAppointmentCountFragmentController.java
public JSONObject saveAppointment(@RequestParam("patient") Patient patient, @RequestParam("date") String date, UiUtils ui) {// w w w .ja va2 s. com Visit activeVisit = null; Encounter enounterAvailable = null; SimpleDateFormat mysqlDateTimeFormatter = new SimpleDateFormat("dd-MMM-yy"); Date dateEntered = null; try { dateEntered = mysqlDateTimeFormatter.parse(date); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } List<Visit> activeVisitList = Context.getVisitService().getActiveVisitsByPatient(patient); for (Visit v : activeVisitList) { activeVisit = v; } List<Obs> obsAllList = Context.getObsService().getObservationsByPersonAndConcept(patient, Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE)); List<Obs> currentVisitObs = new ArrayList<Obs>(); for (Obs o : obsAllList) { if (o.getEncounter().getVisit().equals(activeVisit)) { currentVisitObs.add(o); } } for (Obs o : currentVisitObs) { enounterAvailable = o.getEncounter(); } if (enounterAvailable != null) { Date curDate = new Date(); SimpleDateFormat mysqlDateTimeFormatter1 = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); Date obsDateTime = null; String modifiedDate = new SimpleDateFormat("dd-MMM-yyyy") .format(enounterAvailable.getEncounterDatetime()); try { obsDateTime = mysqlDateTimeFormatter1.parse(modifiedDate + " " + curDate.getHours() + ":" + curDate.getMinutes() + ":" + curDate.getSeconds()); } catch (ParseException e) { obsDateTime = curDate; // TODO Auto-generated catch block e.printStackTrace(); } List<Obs> obsList = Context.getObsService().getObservationsByPersonAndConcept(patient, Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE)); for (Obs o : obsList) { if (o.getEncounter().equals(enounterAvailable)) { o.setVoided(true); o.setVoidReason("updated"); o.setDateVoided(new Date()); o.setVoidedBy(Context.getAuthenticatedUser()); } } Obs obs = new Obs(); obs.setEncounter(enounterAvailable); obs.setObsDatetime(obsDateTime); obs.setPerson(patient); obs.setLocation(Context.getService(KenyaEmrService.class).getDefaultLocation()); obs.setDateCreated(new Date()); obs.setCreator(Context.getAuthenticatedUser()); obs.setValueDatetime(dateEntered); obs.setConcept(Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE)); obs.setComment("next apointment"); Context.getObsService().saveObs(obs, null); } else { Date curDate = new Date(); SimpleDateFormat mysqlDateTimeFormatter1 = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); Date encounterDateTime = null; if (activeVisit != null) { String modifiedDate = new SimpleDateFormat("dd-MMM-yyyy").format(activeVisit.getStartDatetime()); try { encounterDateTime = mysqlDateTimeFormatter1.parse(modifiedDate + " " + curDate.getHours() + ":" + curDate.getMinutes() + ":" + curDate.getSeconds()); } catch (ParseException e) { encounterDateTime = curDate; // TODO Auto-generated catch block e.printStackTrace(); } } Encounter newEncounter = new Encounter(); newEncounter.setEncounterType( Context.getEncounterService().getEncounterTypeByUuid("465a92f2-baf8-42e9-9612-53064be868e8")); newEncounter.setPatient(patient); newEncounter.setLocation(Context.getService(KenyaEmrService.class).getDefaultLocation()); newEncounter.setDateCreated(new Date()); newEncounter.setEncounterDatetime(encounterDateTime); newEncounter.setVisit(activeVisit); newEncounter.setCreator(Context.getAuthenticatedUser()); newEncounter.setVoided(false); enounterAvailable = Context.getEncounterService().saveEncounter(newEncounter); List<Obs> obsList = Context.getObsService().getObservationsByPersonAndConcept(patient, Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE)); for (Obs o : obsList) { if (o.getEncounter().equals(enounterAvailable)) { o.setVoided(true); o.setVoidReason("updated"); o.setDateVoided(new Date()); o.setVoidedBy(Context.getAuthenticatedUser()); } } Obs obs = new Obs(); obs.setEncounter(enounterAvailable); obs.setObsDatetime(encounterDateTime); obs.setPerson(patient); obs.setDateCreated(new Date()); obs.setLocation(Context.getService(KenyaEmrService.class).getDefaultLocation()); obs.setCreator(Context.getAuthenticatedUser()); obs.setValueDatetime(dateEntered); obs.setConcept(Context.getConceptService().getConceptByUuid(Dictionary.RETURN_VISIT_DATE)); obs.setComment("next apointment"); Context.getObsService().saveObs(obs, null); } int totalPatient = 0; JSONObject drugsInfoDetailsJson = new JSONObject(); drugsInfoDetailsJson.put("count", totalPatient); return drugsInfoDetailsJson; }
From source file:org.opencastproject.capture.impl.SchedulerImpl.java
/** * Parses an date to build a cron-like time string. * /*ww w . j a v a 2 s. c om*/ * @param date * The {@code Date} you want returned in a cronstring. * @return A cron-like scheduling string in a {@code CronExpression} object. * @throws ParseException */ public static CronExpression getCronString(Date date) throws ParseException { // TODO: Remove the deprecated calls here. StringBuilder sb = new StringBuilder(); sb.append(date.getSeconds() + " "); sb.append(date.getMinutes() + " "); sb.append(date.getHours() + " "); sb.append(date.getDate() + " "); sb.append(date.getMonth() + 1 + " "); // Note: Java numbers months from 0-11, Quartz uses 1-12. Sigh. sb.append("? "); sb.append(date.getYear() + 1900); // Yay java. return new CronExpression(sb.toString()); }
From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java
@SuppressWarnings("deprecation") private void assertEqualsTime(Date date, int hours, int minutes, int seconds) { assertEquals(hours, date.getHours()); assertEquals(minutes, date.getMinutes()); assertEquals(seconds, date.getSeconds()); }
From source file:com.edgenius.wiki.blogsync.WordpressProxy.java
/** * Return "date_create_gmt" time is gmt, but timezone is wrong - it is local timezone. * Here will correct timezone and return date in local timezone. * @param date/*from www.j a va2 s . co m*/ * @return */ private Date fixInputTimezone(Date date) { if (date == null) return new Date();//??? Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); cal.set(Calendar.YEAR, date.getYear() + 1900); cal.set(Calendar.MONTH, date.getMonth()); cal.set(Calendar.DATE, date.getDate()); cal.set(Calendar.HOUR_OF_DAY, date.getHours()); cal.set(Calendar.MINUTE, date.getMinutes()); cal.set(Calendar.SECOND, date.getSeconds()); Calendar local = Calendar.getInstance(TimeZone.getDefault()); local.setTimeInMillis(cal.getTimeInMillis()); return local.getTime(); }
From source file:com.att.android.arodatacollector.utils.AROCollectorUtils.java
/** * Gets the default ARO trace folder name in the HH:MM:SS:DD:MM:YY format. * /*from w w w .j av a 2s . c om*/ * @return The default ARO trace folder name. */ public String getDefaultTraceFolderName() { final Date systemDate = new Date(); final Calendar now = Calendar.getInstance(); final int currenthours = systemDate.getHours(); final int currentminutes = systemDate.getMinutes(); final int currentseconds = systemDate.getSeconds(); final int currentdate = now.get(Calendar.DATE); // java calendar int currentmonth = now.get(Calendar.MONTH); // As Jan is defined as 0 in currentmonth = currentmonth + 1; if (currentmonth >= 13) // As Jan is defined as 0 in java calendar currentmonth = 1; String currentMonth = Integer.toString(currentmonth); String currentDate = Integer.toString(currentdate); String currentHours = Integer.toString(currenthours); String currentMinutes = Integer.toString(currentminutes); String currentSeconds = Integer.toString(currentseconds - 1); if (currentmonth < 10) { currentMonth = ""; currentMonth = "0" + currentmonth; } if (currentdate < 10) { currentDate = ""; currentDate = "0" + currentdate; } if (currenthours < 10) { currentHours = ""; currentHours = "0" + currenthours; } if (currentminutes < 10) { currentMinutes = ""; currentMinutes = "0" + currentminutes; } if (currentseconds < 10) { currentSeconds = ""; currentSeconds = "0" + currentseconds; } final String folderName = now.get(Calendar.YEAR) + "-" + currentMonth + "-" + currentDate + "-" + currentHours + "-" + currentMinutes + "-" + currentSeconds; return folderName; }
From source file:com.hp.rest.GenericResource.java
@POST @Path("/putImage") @Consumes(MediaType.APPLICATION_JSON)// ww w . ja v a2 s . com public Response putImage(String pData) { // pair to object ObjectMapper mapper = new ObjectMapper(); DataInfo data = new DataInfo(); try { // File jsonFile = new File(jsonFilePath); data = mapper.readValue(pData, DataInfo.class); //System.out.println(track.getMMaKhachHang()); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date today = new Date(); String name = data.getNhanVien() + "-" + df.format(today) + "-" + today.getHours() + "-" + today.getMinutes() + "-" + today.getSeconds() + ".jpg"; String path = ServletActionContext.getServletContext().getRealPath("/db_customers/"); //Create new folder File file = new File(path + "/" + data.getKhachHang()); if (!file.exists()) { if (file.mkdir()) { System.out.println("Directory is created!"); } else { System.out.println("Failed to create directory!"); } } System.out.println(path + "/" + data.getKhachHang() + "/" + name); //Save saveImage(data.getNoiDung(), (path + "/" + data.getKhachHang() + "/" + name)); //Save in database CustomerImageDAO customerImageDAO = new CustomerImageDAOImpl(); CustomerImage customerImage = new CustomerImage(); customerImage.setId(name); customerImage.setName(name); customerImage.setCustomerID(data.getKhachHang()); customerImage.setStaffID(data.getNhanVien()); customerImage.setTime(Timestamp.valueOf(df2.format(today))); customerImage.setStatus(false); boolean status = customerImageDAO.saveOrUpdate(customerImage); //save track staff StaffHistoryDAO staffHistoryDAO = new StaffHistoryDAOImpl(); StaffHistory staffHistory = new StaffHistory(); staffHistory = staffHistoryDAO.getStaffHistory(data.getKhachHang(), df.format(today)); if (staffHistory == null) { byte[] b = data.getTenKhachHang().getBytes(Charset.forName("UTF-8")); String str = new String(b); System.out.println(data.getTenKhachHang() + "\n" + str); staffHistory = new StaffHistory(); staffHistory.setStaff(data.getNhanVien()); staffHistory.setCustomer(data.getKhachHang()); staffHistory.setCustomerName(str); staffHistory.setStartTime(Timestamp.valueOf(df2.format(today))); //staffHistory.setNote(); staffHistoryDAO.saveOrUpdate(staffHistory); } // String output = pTrack.toString(); System.out.println(status + " ____ " + data.getNhanVien() + "___ " + data.getKhachHang()); return Response.status(200).entity("______ Success").build(); }
From source file:eionet.util.Util.java
/** * A method for calculating and formatting the current date and time into a String for a log. *//*from w w w . j a v a 2 s. c o m*/ public static String logTime() { Date date = new Date(); String month = String.valueOf(date.getMonth()); month = (month.length() < 2) ? ("0" + month) : month; String day = String.valueOf(date.getDate()); day = (day.length() < 2) ? ("0" + day) : day; String hours = String.valueOf(date.getHours()); hours = (hours.length() < 2) ? ("0" + hours) : hours; String minutes = String.valueOf(date.getMinutes()); minutes = (minutes.length() < 2) ? ("0" + minutes) : minutes; String seconds = String.valueOf(date.getSeconds()); seconds = (seconds.length() < 2) ? ("0" + seconds) : seconds; String time = "[" + month; time = time + "/" + day; time = time + " " + hours; time = time + ":" + minutes; time = time + ":" + seconds; time = time + "] "; return time; }
From source file:eionet.util.Util.java
/** * A method for formatting the given timestamp into a String for history. * * @param timestamp Milliseconds since 1 January 1970. * @return formatted time as string in the form 2015/04/18 12:43. *///from ww w . j a va 2 s . c om public static String historyDate(long timestamp) { Date date = new Date(timestamp); String year = String.valueOf(1900 + date.getYear()); String month = String.valueOf(date.getMonth() + 1); month = (month.length() < 2) ? ("0" + month) : month; String day = String.valueOf(date.getDate()); day = (day.length() < 2) ? ("0" + day) : day; String hours = String.valueOf(date.getHours()); hours = (hours.length() < 2) ? ("0" + hours) : hours; String minutes = String.valueOf(date.getMinutes()); minutes = (minutes.length() < 2) ? ("0" + minutes) : minutes; String seconds = String.valueOf(date.getSeconds()); seconds = (seconds.length() < 2) ? ("0" + seconds) : seconds; String time = year; time = time + "/" + month; time = time + "/" + day; time = time + " " + hours; time = time + ":" + minutes; return time; }
From source file:opensource.zeocompanion.ZeoCompanionApplication.java
private void configAlarmManagerToPrefs() { // setup a daily alarm if auto-emailing is enabled SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean enabledAutoEmail = prefs.getBoolean("email_auto_enable", false); boolean enabledDatabaseReplicate = prefs.getBoolean("database_replicate_zeo", false); long desiredTOD = prefs.getLong("email_auto_send_time", 0); // will default to midnight long configuredTOD = prefs.getLong("email_auto_send_time_configured", 0); // will default to midnight // determine whether there is an active AlarmManager entry that we have established AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); Intent intentCheck = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class); intentCheck.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC); PendingIntent existingPi = PendingIntent.getBroadcast(this, 0, intentCheck, PendingIntent.FLAG_NO_CREATE); if (enabledAutoEmail || enabledDatabaseReplicate) { // Daily AlarmManager is needed if (existingPi != null && desiredTOD != configuredTOD) { // there is an existing AlarmManager entry, but it has the incorrect starting time-of-day; // so cancel it, and rebuild a new one Intent intent1 = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class); intent1.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC); PendingIntent pi1 = PendingIntent.getBroadcast(this, 0, intent1, PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(pi1);/* ww w . j a v a 2s . c o m*/ pi1.cancel(); existingPi = null; } if (existingPi == null) { // there is no existing AlarmManager entry, so create it Date dt = new Date(desiredTOD); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, dt.getHours()); calendar.set(Calendar.MINUTE, dt.getMinutes()); calendar.set(Calendar.SECOND, dt.getSeconds()); Intent intent2 = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class); intent2.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC); PendingIntent pi2 = PendingIntent.getBroadcast(this, 0, intent2, PendingIntent.FLAG_UPDATE_CURRENT); am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pi2); SharedPreferences.Editor editor = prefs.edit(); editor.putLong("email_auto_send_time_configured", desiredTOD); editor.commit(); } } else { // Daily AlarmManager is not needed if (existingPi != null) { // there is an AlarmManager entry pending; need to cancel it Intent intent3 = new Intent(this, ZeoCompanionApplication.AlarmReceiver.class); intent3.setAction(ZeoCompanionApplication.ACTION_ALARMMGR_WAKEUP_RTC); PendingIntent pi3 = PendingIntent.getBroadcast(this, 0, intent3, PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(pi3); pi3.cancel(); } } }