List of usage examples for java.text DateFormat parse
public Date parse(String source) throws ParseException
From source file:com.dagobert_engine.portfolio.service.MtGoxPortfolioService.java
/** * Get join date//from w w w.j av a 2 s.c om * * @param forceRefresh * @return */ public Date getJoinDate() { DateFormat df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss"); try { return df.parse((String) getData().get("Created")); } catch (java.text.ParseException e) { throw new MtGoxException(e); } }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaBucketDaoTest.java
@Test public void getDropsToDate() throws Exception { Account account = accountDao.findById(1L); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); DropFilter filter = new DropFilter(); filter.setDateTo(dateFormat.parse("01/01/2012")); List<Drop> drops = bucketDao.getDrops(1L, filter, 1, 10, account); assertEquals(1, drops.size());//from w w w . j a v a 2 s.c o m Drop drop = drops.get(0); assertEquals(1, drop.getId()); }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaBucketDaoTest.java
@Test public void getDropsFromDate() throws Exception { Account account = accountDao.findById(1L); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); DropFilter filter = new DropFilter(); filter.setDateFrom(dateFormat.parse("01/01/2013")); List<Drop> drops = bucketDao.getDrops(1L, filter, 1, 10, account); assertEquals(1, drops.size());//w w w . j ava 2 s . com Drop drop = drops.get(0); assertEquals(5, drop.getId()); }
From source file:net.iubris.ipc_d3.timeline.DateToEpochFormatterAndReduceTipiSpecifici.java
private JSONArray adjustTimeAndTipiSpecifici(String dataAsCSV) throws ParseException { JSONArray jsonArray = CDL.toJSONArray(dataAsCSV); int length = jsonArray.length(); JSONArray jsonArrayNew = new JSONArray(); for (int i = 0; i < length; i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); JSONObject jsonObjectNew = new JSONObject(); jsonObjectNew.put("label", jsonObject.getString("nome")); jsonObjectNew.put("indirizzo", jsonObject.getString("indirizzo")); jsonObjectNew.put("numeroCivico", jsonObject.getString("numero-civico")); jsonObjectNew.put("cap", jsonObject.getString("cap")); jsonObjectNew.put("quartiere", jsonObject.getString("quartiere")); jsonObjectNew.put("citta", jsonObject.getString("citta")); jsonObjectNew.put("geolocazione", jsonObject.getString("geolocazione")); jsonObjectNew.put("telefono", jsonObject.getString("telefono")); jsonObjectNew.put("mobile", jsonObject.getString("mobile")); jsonObjectNew.put("email", jsonObject.getString("email")); jsonObjectNew.put("web", jsonObject.getString("web")); jsonObjectNew.put("tipi", jsonObject.getString("tipi")); jsonObjectNew.put("tipiSpecifici", jsonObject.getString("tipi-specifici")); String tipiSpecifici = jsonObject.getString("tipi-specifici"); String tipiSpecificiReduced = ""; switch (tipiSpecifici) { case "Discoteca": tipiSpecificiReduced = "Discoteca"; break; case "Pub, DiscoPub": tipiSpecificiReduced = "DiscoPub"; break; case "Cocktail Bar": tipiSpecificiReduced = "Cocktail"; break; case "Cocktail Bar, American Bar, Ristorante": tipiSpecificiReduced = "American"; break; case "Cocktail Bar, Pizzeria, Ristorante, Panineria": tipiSpecificiReduced = "Panineria"; break; case "Wine Bar, Pub": tipiSpecificiReduced = "Pub"; break; case "Wine Bar": tipiSpecificiReduced = "Wine"; break; default://from w w w . ja v a 2 s. com tipiSpecificiReduced = ""; break; } jsonObjectNew.put("tipiSpecificiReduced", tipiSpecificiReduced); DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String date = "1970-01-01"; JSONArray times = new JSONArray(); String apertura = jsonObject.getString("apertura"); long startingTimeEpoch = 0; if (apertura.isEmpty()) apertura = "19.00"; // default startingTimeEpoch = sdf.parse(date + " " + apertura.replace(".", ":")).getTime(); String chiusura = jsonObject.getString("chiusura"); long endingTimeEpoch = 0; if (chiusura.isEmpty()) chiusura = "1.00"; // default double parsedEndingTime = Double.parseDouble(chiusura); if (parsedEndingTime >= 0f && parsedEndingTime < 6f) // we are in next day date = "1970-01-02"; endingTimeEpoch = sdf.parse(date + " " + chiusura.replace(".", ":")).getTime(); String startingTimeEpoched = "" + startingTimeEpoch; String endingTimeEpoched = "" + endingTimeEpoch; JSONObject et = new JSONObject(); et.put("starting_time", startingTimeEpoched); et.put("ending_time", endingTimeEpoched); times.put(et); jsonObjectNew.put("times", times); jsonArrayNew.put(jsonObjectNew); } return jsonArrayNew; }
From source file:controller.customer.CustomerController.java
@RequestMapping(value = "/FinalBook", method = RequestMethod.GET) public ModelAndView FinalBook(BookingBean bookingbean, HttpSession session) throws ParseException { ModelAndView model = new ModelAndView("Gateway"); Date date = Calendar.getInstance().getTime(); // Display a date in day, month, year format DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); String today = formatter.format(date); //System.out.println("Today : " + today); SimpleDateFormat formatter1 = new SimpleDateFormat("dd/MMM/yyyy"); Date date1 = formatter.parse(today); bookingbean.setBookingDate(date1);/* w w w . j a v a 2 s.c o m*/ System.out.println(date1 + " " + bookingbean.getJourneyDate()); String loginid = (String) session.getAttribute("loginid"); //System.out.println(loginid); bookingbean.setBookingid(loginid.substring(0, 4) + ((Long) (incrementer2.nextLongValue())).toString()); bookingbean.setLoginid(loginid); session.setAttribute("bookingbean", bookingbean); return model; }
From source file:org.openmrs.module.accessmonitor.web.controller.AccessMonitorOrderController.java
@RequestMapping(value = "/module/accessmonitor/order", method = RequestMethod.GET) public void person(ModelMap model, HttpServletRequest request) { offset = 0;//from w w w .jav a2s . c om // parse them to Date, null is acceptable DateFormat format = new SimpleDateFormat("MM/dd/yyyy"); // Get the from date and to date Date to = null; Date from = null; try { from = format.parse(request.getParameter("datepickerFrom")); } catch (Exception e) { //System.out.println("======From Date Empty======="); } try { to = format.parse(request.getParameter("datepickerTo")); } catch (Exception e) { //System.out.println("======To Date Empty======="); } // get all the records in the date range orderAccessData = ((OrderAccessService) Context.getService(OrderAccessService.class)) .getOrderAccessesByAccessDateOrderByPatientId(from, to); if (orderAccessData == null) { orderAccessData = new ArrayList<OrderServiceAccess>(); } // get date for small graph Date toSmall = to; Date fromSmall = null; Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); if (toSmall == null) { toSmall = calendar.getTime(); } else { calendar.setTime(toSmall); } calendar.add(Calendar.DATE, -DAYNUM); fromSmall = calendar.getTime(); List<String> dateStrings = new ArrayList<String>(); for (int i = 0; i < DAYNUM; i++) { if (i == DAYNUM - 1) { dateStrings.add(format.format(toSmall)); } else if (i == 0) { dateStrings.add(format.format(fromSmall)); } else { dateStrings.add(""); } } ArrayList<ArrayList<Integer>> tooltip = new ArrayList<ArrayList<Integer>>(); tooltip.add(new ArrayList<Integer>()); for (int j = 0; j < SHOWNUM + 1; j++) { tooltip.get(0).add(1000 + j); } for (int i = 1; i < DAYNUM + 1; i++) { tooltip.add(new ArrayList<Integer>()); tooltip.get(i).add(i); for (int j = 0; j < SHOWNUM; j++) { tooltip.get(i).add(0); } } ArrayList<String> patientIds = new ArrayList<String>(); ArrayList<Integer> patientCounts = new ArrayList<Integer>(); for (OrderServiceAccess oa : orderAccessData) { // data for big graph String idString = (oa.getPatientId() == null) ? "No ID" : oa.getPatientId().toString(); int index = patientIds.indexOf(idString); if (index < 0) { if (patientIds.size() >= SHOWNUM) break; patientIds.add(idString); patientCounts.add(1); index = patientIds.size() - 1;//index = personIds.indexOf(idString); } else { patientCounts.set(index, patientCounts.get(index) + 1); } // data for small graph if (oa.getAccessDate().after(fromSmall) && oa.getAccessDate().before(toSmall)) { int index2 = (int) ((oa.getAccessDate().getTime() - fromSmall.getTime()) / (1000 * 60 * 60 * 24)); if (index2 < DAYNUM && index2 >= 0) tooltip.get(index2 + 1).set(index + 1, tooltip.get(index2 + 1).get(index + 1) + 1); } } String patientIdString = JSONValue.toJSONString(patientIds); String patientCountString = JSONValue.toJSONString(patientCounts); String dateSmallString = JSONValue.toJSONString(dateStrings); String tooltipdata = JSONValue.toJSONString(tooltip); model.addAttribute("patientIds", patientIdString); model.addAttribute("patientCounts", patientCountString); model.addAttribute("dateSmallString", dateSmallString); model.addAttribute("tooltipdata", tooltipdata); model.addAttribute("user", Context.getAuthenticatedUser()); //model.addAttribute("tables1", orderAccessData); //model.addAttribute("dateSmall", dateStrings); model.addAttribute("currentoffset", String.valueOf(offset)); }
From source file:org.openmrs.module.accessmonitor.web.controller.AccessMonitorPersonController.java
@RequestMapping(value = "/module/accessmonitor/person", method = RequestMethod.GET) public void person(ModelMap model, HttpServletRequest request) { offset = 0;// w w w . j a va2 s .c o m // parse them to Date, null is acceptabl DateFormat format = new SimpleDateFormat("MM/dd/yyyy"); // Get the from date and to date Date to = null; Date from = null; try { from = format.parse(request.getParameter("datepickerFrom")); } catch (Exception e) { //System.out.println("======From Date Empty======="); } try { to = format.parse(request.getParameter("datepickerTo")); } catch (Exception e) { //System.out.println("======To Date Empty======="); } // get all the records in the date range personAccessData = ((PersonAccessService) Context.getService(PersonAccessService.class)) .getPersonAccessesByAccessDateOrderByPersonId(from, to); if (personAccessData == null) { personAccessData = new ArrayList<PersonServiceAccess>(); } // get date for small graph Date toSmall = to; Date fromSmall = null; Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DATE, 1); if (toSmall == null) { toSmall = calendar.getTime(); } else { calendar.setTime(toSmall); } calendar.add(Calendar.DATE, -DAYNUM); fromSmall = calendar.getTime(); List<String> dateStrings = new ArrayList<String>(); for (int i = 0; i < DAYNUM; i++) { if (i == DAYNUM - 1) { dateStrings.add(format.format(toSmall)); } else if (i == 0) { dateStrings.add(format.format(fromSmall)); } else { dateStrings.add(""); } } ArrayList<ArrayList<Integer>> tooltip = new ArrayList<ArrayList<Integer>>(); tooltip.add(new ArrayList<Integer>()); for (int j = 0; j < SHOWNUM + 1; j++) { tooltip.get(0).add(1000 + j); } for (int i = 1; i < DAYNUM + 1; i++) { tooltip.add(new ArrayList<Integer>()); tooltip.get(i).add(i); for (int j = 0; j < SHOWNUM; j++) { tooltip.get(i).add(0); } } ArrayList<String> personIds = new ArrayList<String>(); ArrayList<Integer> personCounts = new ArrayList<Integer>(); for (PersonServiceAccess pa : personAccessData) { // data for big graph String idString = (pa.getPersonId() == null) ? "No ID" : pa.getPersonId().toString(); int index = personIds.indexOf(idString); if (index < 0) { if (personIds.size() >= SHOWNUM) break; personIds.add(idString); personCounts.add(1); index = personIds.size() - 1;//index = personIds.indexOf(idString); } else { personCounts.set(index, personCounts.get(index) + 1); } // data for small graph if (pa.getAccessDate().after(fromSmall) && pa.getAccessDate().before(toSmall)) { int index2 = (int) ((pa.getAccessDate().getTime() - fromSmall.getTime()) / (1000 * 60 * 60 * 24)); if (index2 < DAYNUM && index2 >= 0) tooltip.get(index2 + 1).set(index + 1, tooltip.get(index2 + 1).get(index + 1) + 1); } } String personIdString = JSONValue.toJSONString(personIds); String personCountString = JSONValue.toJSONString(personCounts); String dateSmallString = JSONValue.toJSONString(dateStrings); String tooltipdata = JSONValue.toJSONString(tooltip); model.addAttribute("personIds", personIdString); model.addAttribute("personCounts", personCountString); model.addAttribute("dateSmallString", dateSmallString); model.addAttribute("tooltipdata", tooltipdata); model.addAttribute("user", Context.getAuthenticatedUser()); //model.addAttribute("tables1", personAccessData); //model.addAttribute("dateSmall", dateStrings); model.addAttribute("currentoffset", String.valueOf(offset)); }
From source file:net.bashtech.geobot.JSONUtil.java
public static boolean krakenOutdatedChannel(String channel) { if (BotManager.getInstance().twitchChannels == false) return false; try {/*from w w w . j av a 2s . c o m*/ JSONParser parser = new JSONParser(); Object obj = parser.parse( BotManager.getRemoteContentTwitch("https://api.twitch.tv/kraken/channels/" + channel, 2)); JSONObject jsonObject = (JSONObject) obj; Object statusO = jsonObject.get("status"); Long status; if (statusO != null) { status = (Long) statusO; if (status == 422 || status == 404) { System.out.println("Channel " + channel + " returned status: " + status + ". Parting channel."); return true; } } String updatedAtString = (String) jsonObject.get("updated_at"); DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); format.setTimeZone(java.util.TimeZone.getTimeZone("US/Pacific")); long differenceDay = 0; try { Date then = format.parse(updatedAtString); long differenceSec = (long) (System.currentTimeMillis() / 1000) - (then.getTime() / 1000); differenceDay = (long) (differenceSec / 86400); } catch (Exception exi) { exi.printStackTrace(); } if (differenceDay > 30) { System.out.println( "Channel " + channel + " not updated in " + differenceDay + " days. Parting channel."); return true; } } catch (Exception ex) { return false; } return false; }
From source file:io.vertigo.vega.webservice.WebServiceManagerTest.java
private static String convertDate(final String dateStr) throws ParseException { final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); final Date date = dateFormat.parse(dateStr); final DateFormat dateFormatUtc = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); return dateFormatUtc.format(date); }
From source file:com.cyclopsgroup.waterview.Attributes.java
/** * Get date value with DateFormat/*from w ww .ja v a 2 s.co m*/ * * @param name Attribute name * @param defaultValue Default date value * @param format DateFormat * @return Date object */ public Date getDate(String name, Date defaultValue, DateFormat format) { try { return format.parse(doGetValue(name)); } catch (Exception e) { return defaultValue; } }