List of usage examples for java.util Date toString
public String toString()
where:dow mon dd hh:mm:ss zzz yyyy
From source file:org.hdiv.web.servlet.tags.form.CheckboxTagTests.java
public void testWithObjectUnchecked() throws Exception { this.tag.setPath("date"); Date date = new Date(); this.tag.setValue(date); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getWriter().toString(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element checkboxElement = (Element) document.getRootElement().elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("date", checkboxElement.attribute("name").getValue()); assertNull(checkboxElement.attribute("checked")); assertEquals(date.toString(), checkboxElement.attribute("value").getValue()); }
From source file:com.ibuildapp.romanblack.FanWallPlugin.data.Statics.java
public static String getTwitterFormattedDate(Date date, Context ctx) { // if date not found if (date == null) { date = new Date(); }/* w w w.ja v a 2 s.c o m*/ try { String ttt = ctx.getResources().getString(R.string.romanblack_twitter_date_minutes); ttt = ctx.getResources().getString(R.string.romanblack_twitter_date_minutes); long delta = (System.currentTimeMillis() - date.getTime()) / 1000; String strPubdate; if (delta <= 0) { strPubdate = 0 + ctx.getString(R.string.romanblack_twitter_date_seconds); return strPubdate; } if (delta < 60) { strPubdate = delta + ctx.getString(R.string.romanblack_twitter_date_seconds); } else if (delta < 120) { strPubdate = 1 + ctx.getString(R.string.romanblack_twitter_date_minutes); } else if (delta < (45 * 60)) { strPubdate = (int) (delta / 60) + ctx.getString(R.string.romanblack_twitter_date_minutes); } else if (delta < (2 * 60 * 60)) { strPubdate = 1 + ctx.getString(R.string.romanblack_twitter_date_hour_ago); } else if (delta < (24 * 60 * 60)) { strPubdate = (int) (delta / 3600) + ctx.getString(R.string.romanblack_twitter_date_hour_ago); } else { SimpleDateFormat simpleDateFormat = new SimpleDateFormat( ctx.getString(R.string.twitter_date_format_item)); strPubdate = simpleDateFormat.format(date); } return strPubdate; } catch (Exception ex) { return date.toString(); } }
From source file:ddf.catalog.source.opensearch.CddaOpenSearchSite.java
/** * Creates a single response from input parameters. Performs XPath operations on the document to * retrieve data not passed in.//from ww w . j ava 2s. c o m * * @param inputDoc * DDMS based Document * @param id * id for the entry * @param dateStr * String value of the date * @param relevance * Relevance score (0 if N/A) * @return single response */ private Result createResponse(Document inputDoc, String id, String dateStr, String relevance) { final MetacardImpl metacard = new MetacardImpl(); metacard.setMetadata(XPathHelper.xmlToString(inputDoc)); String title = evaluate(OpenSearchSiteUtil.XPATH_TITLE, inputDoc); metacard.setTitle(title); metacard.setId(id); Date modifiedDate = OpenSearchSiteUtil.parseDate(dateStr); if (modifiedDate != null) { metacard.setModifiedDate(modifiedDate); } if (logger.isDebugEnabled()) { logger.debug("title = [" + title + "]"); logger.debug("id = [" + id + "]"); logger.debug("date = [" + dateStr + "]"); if (modifiedDate != null) { logger.debug("modifiedDate = " + modifiedDate.toString()); } else { logger.debug("modifiedDate is NULL"); } } metacard.setSourceId(this.shortname); ResultImpl result = new ResultImpl(metacard); if (relevance == null || relevance.isEmpty()) { logger.debug("couldn't find valid relevance. Setting relevance to 0"); relevance = "0"; } result.setRelevanceScore(new Double(relevance)); return result; }
From source file:dk.netarkivet.harvester.scheduler.jobgen.AbstractJobGenerator.java
@Override public int generateJobs(HarvestDefinition harvest) { log.info("Generating jobs for harvestdefinition # " + harvest.getOid()); int jobsMade = 0; final Iterator<DomainConfiguration> domainConfigurations = harvest.getDomainConfigurations(); while (domainConfigurations.hasNext()) { List<DomainConfiguration> subset = new ArrayList<DomainConfiguration>(); while (domainConfigurations.hasNext() && subset.size() < DOMAIN_CONFIG_SUBSET_SIZE) { subset.add(domainConfigurations.next()); }/*w w w.j av a 2 s . c o m*/ Collections.sort(subset, getDomainConfigurationSubsetComparator(harvest)); if (log.isTraceEnabled()) { log.trace(subset.size() + " domainconfigs now sorted and ready to processing " + "for harvest #" + harvest.getOid()); } jobsMade += processDomainConfigurationSubset(harvest, subset.iterator()); } harvest.setNumEvents(harvest.getNumEvents() + 1); if (!harvest.isSnapShot()) { PartialHarvest focused = (PartialHarvest) harvest; Schedule schedule = focused.getSchedule(); int numEvents = harvest.getNumEvents(); //Calculate next event Date now = new Date(); Date nextEvent = schedule.getNextEvent(focused.getNextDate(), numEvents); //Refuse to schedule event in the past if (nextEvent != null && nextEvent.before(now)) { int eventsSkipped = 0; while (nextEvent != null && nextEvent.before(now)) { nextEvent = schedule.getNextEvent(nextEvent, numEvents); eventsSkipped++; } if (log.isWarnEnabled()) { log.warn("Refusing to schedule harvest definition '" + harvest.getName() + "' in the past. Skipped " + eventsSkipped + " events. Old nextDate was " + focused.getNextDate() + " new nextDate is " + nextEvent); } } //Set next event focused.setNextDate(nextEvent); if (log.isTraceEnabled()) { log.trace("Next event for harvest definition " + harvest.getName() + " happens: " + (nextEvent == null ? "Never" : nextEvent.toString())); } } log.info("Finished generating " + jobsMade + " jobs for harvestdefinition # " + harvest.getOid()); return jobsMade; }
From source file:org.asqatasun.websnapshot.entity.service.ImageDataServiceImpl.java
@Override public Image getImageFromWidthAndHeightAndUrlAndDate(int width, int height, String url, Date date) { Object object = ((ImageDAO) entityDao).findImageFromDateAndUrlAndWidthAndHeight(url, date, width, height); try {/* w ww .j ava 2 s.c om*/ Image image = (Image) object; if (image.getStatus().equals(Status.CREATED) || image.getStatus().equals(Status.IN_PROGRESS)) { return image; } } catch (Exception ex) { LOGGER.debug( "Impossible to cast object returning from findImageFromDateAndUrlAndWidthAndHeight to Image"); try { Status status = (Status) object; if (status.equals(Status.MUST_BE_CREATE)) { return getImage(url, width, height); } else if (status.equals(Status.NOT_EXIST)) { return null; } else { LOGGER.debug("The requested image with width: " + width + " height: " + height + " url: " + url + " date: " + date.toString() + " hasn't been found and we returned null"); return null; } } catch (Exception ex1) { LOGGER.debug( "Impossible to cast object returning from findImageFromDateAndUrlAndWidthAndHeight to Status"); } } return null; }
From source file:gov.utah.dts.sdc.actions.BaseCommercialStudentAction.java
public String updateTrainingTime() throws Exception { log.debug("insertTrainingTime"); // log.debug("observationDate truncated "+ // truncateDate(getObservationDate())); int start = decodeTime(trainingStartTime); Date startDate = new Date(getTrainingDate().getTime() + start); log.debug("startDate " + startDate.toString()); int end = decodeTime(trainingEndTime); Date endDate = new Date(getTrainingDate().getTime() + end); log.debug("endDate " + endDate.toString()); if (endDate.before(startDate)) { addActionError("Start Time Must Be Before End Time"); } else {/*from w w w . j a v a2 s. co m*/ Map<String, Object> hm = new HashMap<String, Object>(); hm.put("trainingStartTime", startDate); hm.put("trainingEndTime", endDate); hm.put("section", section); hm.put("vehicleFk", vehicleFk); hm.put("instructorFk", instructorFk); hm.put("classroomFk", classroomPk); hm.put("branchFk", branchFk); hm.put("studentFk", studentPk); hm.put("timePk", timePk); hm.put("training_userid", ((Person) getSession().get(Constants.USER_KEY)).getEmail()); hm.put("training_datestamp", new Date()); getStudentService().updateTraining(hm); } if (hasErrors()) { return INPUT; } else { StringBuffer sb = new StringBuffer(); sb.append("<br/>Training Times Updated For Student"); Collection<Object> col = new ArrayList<Object>(); col.add(sb); setCommercialAjaxMessages(col); return SUCCESS; } }
From source file:gov.utah.dts.sdc.actions.BaseCommercialStudentAction.java
public String updateObservationTime() throws Exception { log.debug("updateObservationTime"); log.debug("updateObservationTime StartTime " + observationStartTime); int start = decodeTime(observationStartTime); log.debug("updateObservationTime StartTime decoded"); Date startDate = new Date(getObservationDate().getTime() + start); log.debug("startDate " + startDate.toString()); int end = decodeTime(observationEndTime); Date endDate = new Date(getObservationDate().getTime() + end); log.debug("endDate " + endDate.toString()); if (endDate.before(startDate)) { addActionError("Start Time Must Be Before End Time"); } else {//from w ww . j a va2 s. c o m Map<String, Object> hm = new HashMap<String, Object>(); hm.put("observationStartTime", startDate); hm.put("observationEndTime", endDate); hm.put("vehicleFk", vehicleFk); hm.put("instructorFk", instructorFk); hm.put("classroomFk", classroomPk); hm.put("branchFk", branchFk); hm.put("studentFk", studentPk); hm.put("timePk", timePk); hm.put("observation_userid", ((Person) getSession().get(Constants.USER_KEY)).getEmail()); hm.put("observation_datestamp", new Date()); getStudentService().updateObservation(hm); } if (hasErrors()) { return INPUT; } else { StringBuffer sb = new StringBuffer(); sb.append("<br/>Observation Times Updated For Student"); Collection<Object> col = new ArrayList<Object>(); col.add(sb); setCommercialAjaxMessages(col); return SUCCESS; } }
From source file:gov.utah.dts.sdc.actions.BaseCommercialStudentAction.java
public String updateBTWTime() throws Exception { log.debug("updateBtwTime"); // log.debug("observationDate truncated "+ // truncateDate(getObservationDate())); int start = decodeTime(behindTheWheelStartTime); Date startDate = new Date(getBehindTheWheelDate().getTime() + start); log.debug("startDate " + startDate.toString()); int end = decodeTime(behindTheWheelEndTime); Date endDate = new Date(getBehindTheWheelDate().getTime() + end); log.debug("endDate " + endDate.toString()); if (endDate.before(startDate)) { addActionError("Start Time Must Be Before End Time"); } else {/*w ww. jav a 2 s . com*/ Map<String, Object> hm = new HashMap<String, Object>(); hm.put("btwStartTime", startDate); hm.put("btwEndTime", endDate); hm.put("vehicleFk", vehicleFk); hm.put("instructorFk", instructorFk); hm.put("branchFk", branchFk); hm.put("studentFk", studentPk); hm.put("timePk", timePk); hm.put("btw_userid", ((Person) getSession().get(Constants.USER_KEY)).getEmail()); hm.put("btw_datestamp", new Date()); getStudentService().updateBehindTheWheel(hm); } if (hasErrors()) { return INPUT; } else { StringBuffer sb = new StringBuffer(); sb.append("<br/>Behind The Wheel Times Updated For Student "); Collection<Object> col = new ArrayList<Object>(); col.add(sb); setCommercialAjaxMessages(col); return SUCCESS; } }
From source file:gov.utah.dts.sdc.actions.BaseCommercialStudentAction.java
public String insertObservationTime() throws Exception { log.debug("insertObservationTime"); // log.debug("observationDate truncated "+ // truncateDate(getObservationDate())); int start = decodeTime(observationStartTime); Date startDate = new Date(getObservationDate().getTime() + start); log.debug("startDate " + startDate.toString()); int end = decodeTime(observationEndTime); Date endDate = new Date(getObservationDate().getTime() + end); log.debug("endDate " + endDate.toString()); if (endDate.before(startDate)) { addActionError("Start Time Must Be Before End Time"); } else {//from www . jav a 2 s . c om Map<String, Object> hm = new HashMap<String, Object>(); hm.put("observationStartTime", startDate); hm.put("observationEndTime", endDate); hm.put("vehicleFk", vehicleFk); hm.put("instructorFk", instructorFk); hm.put("classroomFk", classroomPk); hm.put("branchFk", branchFk); hm.put("observation_userid", ((Person) getSession().get(Constants.USER_KEY)).getEmail()); hm.put("observation_datestamp", new Date()); for (int x = 0; x < studentArray.size(); x++) { hm.put("studentFk", studentArray.get(x)); getStudentService().insertObservation(hm); } } if (hasErrors()) { return INPUT; } else { StringBuffer sb = new StringBuffer(); sb.append("<br/>Observation Times Added For "); sb.append(studentArray.size()); if (studentArray.size() == 1) { sb.append(" Student"); } else { sb.append(" Students"); } Collection<Object> col = new ArrayList<Object>(); col.add(sb); setCommercialAjaxMessages(col); return SUCCESS; } }
From source file:gov.utah.dts.sdc.actions.BaseCommercialStudentAction.java
public String insertBtwTime() throws Exception { log.debug("insertBtwTime"); // log.debug("observationDate truncated "+ // truncateDate(getObservationDate())); int start = decodeTime(behindTheWheelStartTime); Date startDate = new Date(getBehindTheWheelDate().getTime() + start); log.debug("startDate " + startDate.toString()); int end = decodeTime(behindTheWheelEndTime); Date endDate = new Date(getBehindTheWheelDate().getTime() + end); log.debug("endDate " + endDate.toString()); if (endDate.before(startDate)) { addActionError("Start Time Must Be Before End Time"); } else {// w ww .java 2s .c o m Map<String, Object> hm = new HashMap<String, Object>(); hm.put("btwStartTime", startDate); hm.put("btwEndTime", endDate); hm.put("vehicleFk", vehicleFk); hm.put("instructorFk", instructorFk); hm.put("classroomFk", classroomPk); hm.put("branchFk", branchFk); hm.put("btw_userid", ((Person) getSession().get(Constants.USER_KEY)).getEmail()); hm.put("btw_datestamp", new Date()); for (int x = 0; x < studentArray.size(); x++) { hm.put("studentFk", studentArray.get(x)); getStudentService().insertBehindTheWheel(hm); } } if (hasErrors()) { return INPUT; } else { StringBuffer sb = new StringBuffer(); sb.append("<br/>Behind The Wheel Times Added For "); sb.append(studentArray.size()); if (studentArray.size() == 1) { sb.append(" Student"); } else { sb.append(" Students"); } Collection<Object> col = new ArrayList<Object>(); col.add(sb); setCommercialAjaxMessages(col); return SUCCESS; } }