List of usage examples for java.text DateFormat parse
public Date parse(String source) throws ParseException
From source file:hh.learnj.test.license.test.alps.hd.LicenseAware.java
@Override public License verify(String key, String fileName) { List<String> list = read(fileName); if (null == list || list.isEmpty() || list.size() < 2) { throw new UnsupportedOperationException("???"); }// www. j a v a 2 s .co m String sign = list.get(0); String target = list.get(1); if (!getCryption().verify(key, target, sign)) { throw new IllegalArgumentException("???"); } String info = getCryption().decryptByPublic(key, target); if (StringUtils.isBlank(info)) { throw new IllegalArgumentException("???"); } String[] infos = info.split(SPLITOR); if (null == infos || infos.length < 7) { throw new IllegalArgumentException("???"); } String serialNumber = infos[0]; String systemSerialNumber = infos[1]; String identifier = infos[2]; String baseboardSerialNumber = infos[3]; if (getHardware().getSerialNumber().equals(serialNumber) && getHardware().getSystemSerialNumber().equals(systemSerialNumber) && getHardware().getIdentifier().equals(identifier) && getHardware().getBaseboardSerialNumber().equals(baseboardSerialNumber)) { String begin = infos[4]; String end = infos[5]; String number = infos[6]; DateFormat dateFormat = new SimpleDateFormat(YYYY_MM_DD); try { License license = new License(); license.setBegin(dateFormat.parse(begin)); license.setEnd(dateFormat.parse(end)); license.setNumber(Integer.parseInt(number)); return license; } catch (Exception e) { e.printStackTrace(); } } return null; }
From source file:org.motechproject.mobile.core.dao.hibernate.MessageRequestDAOImplTest.java
@Before public void setUp() { lDAO = coreManager.createLanguageDAO(); lg1.setId(80000000001l);//w ww.j a v a 2s. c o m lg1.setCode("it"); ntDao = coreManager.createNotificationTypeDAO(); nt1.setId(9878L); nt1.setName("pregnancy"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); try { datefrom1 = df.parse("2009-08-21"); datefrom2 = df.parse("2009-09-04"); dateto1 = df.parse("2009-10-30"); dateto2 = df.parse("2009-11-04"); schedule = df.parse("2009-10-02"); } catch (ParseException e) { e.printStackTrace(); } mrDAO = coreManager.createMessageRequestDAO(); mr1.setId(80000000002l); mr1.setDateCreated(new Date()); mr1.setLanguage(lg1); mr1.setRecipientName("jlkj"); mr1.setRecipientId("r1"); mr1.setMessageType(t); mr2.setId(80000000003l); mr2.setDateCreated(new Date()); mr2.setLanguage(lg1); mr2.setRecipientName("jojo"); mr2.setRecipientId("r2"); mr2.setMessageType(t); mr2.setDateFrom(datefrom1); mr2.setDateTo(dateto1); mr2.setStatus(sta); mr2.setSchedule(schedule); mr3.setId(80000000004l); mr3.setDateCreated(new Date()); mr3.setLanguage(lg1); mr3.setRecipientName("joseph"); mr3.setRecipientId("r3"); mr3.setMessageType(t); mr3.setDateFrom(datefrom2); mr3.setDateTo(dateto2); mr3.setStatus(sta); mr3.setSchedule(schedule); mr4.setId(80000000005l); mr4.setDateCreated(new Date()); mr4.setLanguage(lg1); mr4.setRecipientName("jimmy hendrix"); mr4.setRecipientId("r4"); mr4.setMessageType(t); mr4.setDateFrom(datefrom2); mr4.setDateTo(dateto2); mr4.setStatus(MStatus.INVALIDNET); mr4.setSchedule(schedule); mr4.setTryNumber(2); mr5.setId(80000000006l); mr5.setDateCreated(new Date()); mr5.setLanguage(lg1); mr5.setRecipientName("Kodjo"); mr5.setRecipientId("r5"); mr5.setMessageType(t); mr5.setStatus(MStatus.INVALIDNET); mr5.setSchedule(schedule); mr5.setTryNumber(1); lDAO.save(lg1); ntDao.save(nt1); mrDAO.save(mr2); mrDAO.save(mr3); mrDAO.save(mr4); mrDAO.save(mr5); expResult = new ArrayList(); expResult.add(mr2); expResult.add(mr3); }
From source file:com.chortitzer.web.usi.controller.ConsumoNisBean.java
public List<ConsumoNisModel> getConsumoNisList(Boolean listaCompleta) { try {/*from www . j a v a 2 s . c o m*/ List<Object[]> list; if (listaCompleta) { list = tblIndUsiRegistroLecturasRepository.getConsumoNisCompleto(selectedMes, selectedAno); } else { list = tblIndUsiRegistroLecturasRepository.getConsumoNisComInd(selectedMes, selectedAno); } consumoNisList = new ArrayList<>(); list.stream().forEach((o) -> { ConsumoNisModel cnm = new ConsumoNisModel(); cnm.setNis(o[0].toString()); final DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { cnm.setFechahora(format.parse(o[1].toString())); } catch (Exception ex) { LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", ex.getMessage())); } cnm.setNrserie((BigInteger) o[2]); cnm.setUsuario(o[3].toString()); cnm.setKwh((int) o[4]); cnm.setKvar((int) o[5]); cnm.setConsumo(o[6] != null ? (int) o[6] : 0); consumoNisList.add(cnm); }); return consumoNisList; } catch (Exception ex) { LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", ex.getMessage())); return null; } }
From source file:com.luna.common.repository.UserRepository2ImplForDefaultSearchIT.java
@Test public void testLtAndGtForDate() throws ParseException { int count = 15; String dateStr = "2012-01-15 16:59:00"; String dateStrFrom = "2012-01-15 16:58:00"; String dateStrEnd = "2012-01-15 16:59:01"; DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (int i = 0; i < count; i++) { User user = createUser();// w ww . j a va 2s . c o m user.getBaseInfo().setBirthday(new Timestamp(df.parse(dateStr).getTime())); userRepository2.save(user); } Map<String, Object> searchParams = new HashMap<String, Object>(); searchParams.put("baseInfo.birthday_gt", dateStrFrom); searchParams.put("baseInfo.birthday_lt", dateStrEnd); Searchable search = Searchable.newSearchable(searchParams); assertEquals(count, userRepository2.countAllByDefault(search)); }
From source file:com.luna.common.repository.UserRepository2ImplForDefaultSearchIT.java
@Test public void testLteAndGteForDate() throws ParseException { int count = 15; String dateStr = "2012-01-15 16:59:00"; String dateStrFrom = "2012-01-15 16:59:00"; String dateStrEnd = "2012-01-15 16:59:00"; DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); for (int i = 0; i < count; i++) { User user = createUser();// w w w.j av a 2s. c om user.getBaseInfo().setBirthday(new Timestamp(df.parse(dateStr).getTime())); userRepository2.save(user); } Map<String, Object> searchParams = new HashMap<String, Object>(); searchParams.put("baseInfo.birthday_gte", dateStrFrom); searchParams.put("baseInfo.birthday_lte", dateStrEnd); Searchable search = Searchable.newSearchable(searchParams); assertEquals(count, userRepository2.countAllByDefault(search)); }
From source file:com.haulmont.chile.core.datatypes.impl.DateDatatype.java
@Override public Date parse(String value) throws ParseException { if (StringUtils.isBlank(value)) { return null; }/* www. j a va 2 s . com*/ DateFormat format; if (formatPattern != null) { format = new SimpleDateFormat(formatPattern); format.setLenient(false); } else { format = DateFormat.getDateInstance(); } return normalize(format.parse(value.trim())); }
From source file:edu.harvard.hms.dbmi.bd2k.irct.model.result.tabular.MemoryResultSet.java
@Override public Date getDate(int columnIndex) throws ResultSetException { String dateString = getString(columnIndex); PrimitiveDataType dt = getColumn(columnIndex).getDataType(); String pattern = null;/*from www . j a v a 2s. com*/ if (dt == PrimitiveDataType.DATE) { pattern = "YYYY-MM-dd"; } else if (dt == PrimitiveDataType.DATETIME) { pattern = "YYYY-MM-dd HH:mm:ss"; } else if (dt == PrimitiveDataType.TIME) { pattern = "HH:mm:ss"; } DateFormat formatter = new SimpleDateFormat(pattern); try { return formatter.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return null; }
From source file:gov.whitehouse.ui.fragments.app.ArticleViewerFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Bundle args = getArguments();/* ww w . j av a 2 s .co m*/ mPageInfo = new JSONObject(); try { mPageInfo.put("title", args.getString("title")); final SimpleDateFormat date = new SimpleDateFormat("MMM d, yyyy h:mm a"); final DateFormat parse = DateFormat.getDateTimeInstance(); mPageInfo.put("date", date.format(parse.parse(args.getString("date")))); mPageInfo.put("creator", args.getString("creator")); mPageInfo.put("description", args.getString("description")); mPageInfo.put("url", args.getString("url")); mWebView.loadUrl(PAGE_TEMPLATE_URL); } catch (JSONException e) { Log.e(TAG, "error creating JSON object for post", e); } catch (ParseException e) { } mArticleType = args.getInt(ARG_FEED_TYPE, ARTICLE_TYPE_FEED); mUpTitle = args.getString(ARG_UP_TITLE); if (!((BaseActivity) getSherlockActivity()).isMultipaned()) { switch (mArticleType) { case ARTICLE_TYPE_FEED: getSherlockActivity().getSupportActionBar().setTitle(mUpTitle.toUpperCase()); break; case ARTICLE_TYPE_FAVORITES: getSherlockActivity().getSupportActionBar().setTitle(R.string.favorites); break; } } final String json = args.getString(ARG_ITEM_JSON); if (json != null) { mFeedItem = GsonUtils.fromJson(json, FeedItem.class); } mFavorited = FavoritesUtils.isFavorited(getSherlockActivity(), mFeedItem); }
From source file:com.edgenius.wiki.ext.calendar.web.CalendarAction.java
public String quickUpdate() { QuickReturnJson json = new QuickReturnJson(); CalendarEvent evt = calendarService.getEvent(calendarId); if (evt == null) { json.setIsSuccess(false);//from w w w . j ava 2 s .c o m json.setMsg("Unable to get event"); } else { try { DateFormat format = getDateFormat(); Date start = format.parse(calendarStartTime); Date end = format.parse(calendarEndTime); evt.setStart(start); evt.setEnd(end); WikiUtil.setTouchedInfo(userReadingService, evt); calendarService.saveOrUpdateEvent(evt); json.setIsSuccess(true); json.setMsg("Update success"); } catch (ParseException e) { json.setIsSuccess(false); json.setMsg("Unable to get valid event start/end date"); log.error("Unable to parse calendar start/end date format", e); } } try { Gson gson = new Gson(); String jsonstr = gson.toJson(json); getResponse().getOutputStream().write(jsonstr.getBytes(Constants.UTF8)); } catch (IOException e) { log.error("unable response event save request", e); } return null; }
From source file:com.kmaismith.chunkclaim.Data.DataManagerTest.java
@Test public void testReadPlayerDataWillReadPlayerDataForPlayer() { // Sample player file stolen from a player String playerFileContents = "2014.02.16.18.49.49\n" + "2014.03.13.02.25.21\n" + "5\n" + "\n" + "=========="; try {/*from w w w. j a v a 2 s. c om*/ PrintWriter playerFile = new PrintWriter( PlayerData.playerDataFolderPath + File.separator + "playerA.dat"); playerFile.print(playerFileContents); playerFile.close(); } catch (FileNotFoundException e) { assert false; } DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); Date loginDate = new Date(); try { loginDate = dateFormat.parse("2014.02.16.18.49.49"); } catch (ParseException parseException) { assert false; } PlayerData player = systemUnderTest.readPlayerData("playerA"); systemUnderTest.savePlayerData(player); systemUnderTest.clearCachedPlayerData("playerA"); Assert.assertEquals(player.getFirstJoin(), loginDate); }