List of usage examples for java.text DateFormat SHORT
int SHORT
To view the source code for java.text DateFormat SHORT.
Click Source Link
From source file:org.glom.web.server.libglom.Document.java
private void setNodeTextChildAsValue(final Element element, final DataItem value, final GlomFieldType type) { String str = ""; switch (type) { case TYPE_BOOLEAN: { str = value.getBoolean() ? "true" : "false"; break;//from www.j a v a 2 s. co m } case TYPE_DATE: { // TODO: This is not really the format used by the Glom document: final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ROOT); str = dateFormat.format(value.getDate()); break; } case TYPE_IMAGE: { str = ""; // TODO break; } case TYPE_NUMERIC: { str = getStringForDecimal(value.getNumber()); break; } case TYPE_TEXT: str = value.getText(); break; case TYPE_TIME: str = ""; // TODO break; default: Log.error(documentID, "setNodeTextChildAsValue(): unexpected or invalid field type."); break; } final String escaped = str.replace(QUOTE_FOR_FILE_FORMAT, QUOTE_FOR_FILE_FORMAT + QUOTE_FOR_FILE_FORMAT); element.setTextContent(escaped); }
From source file:us.mn.state.health.lims.common.util.SystemConfiguration.java
public String getPatternForDateLocale() { DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, getDateLocale()); // yyyy/mm/dd Date date = Date.valueOf("2000-01-02"); String pattern = dateFormat.format(date); pattern = pattern.replaceFirst("01", "MM"); pattern = pattern.replaceFirst("02", "DD"); pattern = pattern.replaceFirst("00", "YYYY"); return pattern; }
From source file:org.wso2.carbon.registry.activities.services.utils.ActivityBeanPopulator.java
/** * Converts given strings to Dates//from w w w .j av a 2s .co m * * @param dateString Allowed format mm/dd/yyyy * @return Date corresponding to the given string date */ private static Date computeDate(String dateString) throws RegistryException { if (dateString == null || dateString.length() == 0) { return null; } DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH); try { return formatter.parse(dateString); } catch (ParseException e) { String msg = "Date format is invalid: " + dateString; throw new RegistryException(msg, e); } }
From source file:org.tellervo.desktop.print.SeriesReport.java
/** * iText paragraph containing created and lastmodified timestamps * //from w ww . ja v a 2 s . co m * @return Paragraph */ private Paragraph getTimestampPDF() { // Set up calendar Date createdTimestamp = s.getSeries().getCreatedTimestamp().getValue().toGregorianCalendar().getTime(); Date lastModifiedTimestamp = s.getSeries().getLastModifiedTimestamp().getValue().toGregorianCalendar() .getTime(); DateFormat df1 = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT); Paragraph p = new Paragraph(); p.add(new Chunk("Created: ", subSubSectionFont)); p.add(new Chunk(df1.format(createdTimestamp), bodyFont)); p.add(new Chunk("\nLast Modified: ", subSubSectionFont)); p.add(new Chunk(df1.format(lastModifiedTimestamp), bodyFont)); return p; }
From source file:com.intuit.tank.harness.APITestHarness.java
/** * Run concurrent test plans at the same time * /*ww w . j av a2 s. c o m*/ * @param parser */ public void runConcurrentTestPlans() { if (started) { LOG.warn("Agent already started. Ignoring start command"); return; } tpsMonitor = new TPSMonitor(tankConfig.getAgentConfig().getTPSPeriod()); StringBuilder info = new StringBuilder().append(" RAMP_TIME=").append(agentRunData.getRampTime()) .append("; agentRunData.getNumUsers()=").append(agentRunData.getNumUsers()) .append("; NUM_START_THREADS=").append(agentRunData.getNumStartUsers()).append("; simulationTime=") .append(agentRunData.getSimulationTime()); LOG.info(LogUtil.getLogMessage("starting test with " + info.toString())); started = true; if (agentRunData.getJobId() == null) { String jobId = AmazonUtil.getJobId(); agentRunData.setJobId(jobId); } TestPlanRunner[] sessions = new TestPlanRunner[agentRunData.getNumUsers()]; sessionThreads = new Thread[agentRunData.getNumUsers()]; Thread monitorThread = null; doneSignal = new CountDownLatch(agentRunData.getNumUsers()); try { HDWorkload hdWorkload = TestPlanSingleton.getInstance().getTestPlans().get(0); if (StringUtils.isBlank(tankHttpClientClass)) { tankHttpClientClass = hdWorkload.getTankHttpClientClass(); } agentRunData.setProjectName(hdWorkload.getName()); agentRunData.setTankhttpClientClass(tankHttpClientClass); List<TestPlanStarter> testPlans = new ArrayList<TestPlanStarter>(); int total = 0; for (HDTestPlan plan : hdWorkload.getPlans()) { if (plan.getUserPercentage() > 0) { plan.setVariables(hdWorkload.getVariables()); TestPlanStarter starter = new TestPlanStarter(plan, agentRunData.getNumUsers()); total += starter.getNumThreads(); testPlans.add(starter); LOG.info(LogUtil.getLogMessage("Users for Test Plan " + plan.getTestPlanName() + " at " + plan.getUserPercentage() + "% = " + starter.getNumThreads())); } } LOG.info(LogUtil.getLogMessage("Total Users calculated for all test Plans = " + total)); if (total != agentRunData.getNumUsers()) { int numToAdd = agentRunData.getNumUsers() - total; TestPlanStarter starter = testPlans.get(testPlans.size() - 1); LOG.info(LogUtil.getLogMessage( "adding " + numToAdd + " threads to testPlan " + starter.getPlan().getTestPlanName())); starter.setNumThreads(starter.getNumThreads() + numToAdd); } // create threads int tp = 0; for (TestPlanStarter starter : testPlans) { for (int i = 0; i < starter.getNumThreads(); i++) { sessions[tp] = new TestPlanRunner(starter.getPlan(), tp); sessionThreads[tp] = new Thread(threadGroup, sessions[tp], "AGENT"); sessionThreads[tp].setDaemon(true);// system won't shut down normally until all user threads stop starter.addThread(sessionThreads[tp]); sessions[tp].setUniqueName( sessionThreads[tp].getThreadGroup().getName() + "-" + sessionThreads[tp].getId()); tp++; } } LOG.info(LogUtil.getLogMessage("Have all testPlan runners configured")); // start status thread first only if (!isLocal && !isDebug() && NumberUtils.isDigits(agentRunData.getJobId())) { LOG.info(LogUtil.getLogMessage("Starting monitor thread...")); CloudVmStatus status = getInitialStatus(); monitorThread = new Thread(new APIMonitor(status)); monitorThread.setDaemon(true); monitorThread.setPriority(Thread.NORM_PRIORITY - 2); monitorThread.start(); } LOG.info(LogUtil.getLogMessage("Starting threads...")); // start initial users startTime = System.currentTimeMillis(); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM); LOG.info(LogUtil.getLogMessage("Simulation start: " + df.format(new Date(getStartTime())))); if (agentRunData.getSimulationTime() != 0) { LOG.info(LogUtil.getLogMessage( "Scheduled Simulation End : " + df.format(new Date(getSimulationEndTimeMillis())))); LOG.info(LogUtil.getLogMessage( "Max Simulation End : " + df.format(new Date(getMaxSimulationEndTimeMillis())))); } else { LOG.info(LogUtil.getLogMessage("Ends at script loops completed with no Max Simulation Time.")); } currentNumThreads = 0; if (agentRunData.getNumUsers() > 0) { for (TestPlanStarter starter : testPlans) { if (isDebug()) { starter.run(); } else { Thread t = new Thread(starter); t.setDaemon(true); t.start(); } } boolean ramping = true; while (ramping) { boolean done = true; for (TestPlanStarter starter : testPlans) { done = done && starter.isDone(); } ramping = !done; if (ramping) { Thread.sleep(5000); } } // if we broke early, fix our countdown latch int numToCount = 0; for (TestPlanStarter starter : testPlans) { numToCount += starter.getThreadsStarted(); } while (numToCount < agentRunData.getNumUsers()) { doneSignal.countDown(); numToCount++; } // wait for them to finish LOG.info(LogUtil.getLogMessage("Ramp Complete...")); doneSignal.await(); } } catch (Throwable t) { LOG.error("error executing..." + t, t); } finally { LOG.info(LogUtil.getLogMessage("Test Complete...")); if (!isDebug() && NumberUtils.isDigits(agentRunData.getJobId())) { if (null != monitorThread) { APIMonitor.setJobStatus(JobStatus.Completed); APIMonitor.setDoMonitor(false); } sendBatchToDB(false); // sleep for 60 seconds to let wily agent clear any data try { Thread.sleep(60000); } catch (InterruptedException e) { // nothing to do } } } flowControllerTemplate.endTest(); // System.exit(0); }
From source file:org.madsonic.ajax.PlayQueueService.java
public String savePlaylist() { HttpServletRequest request = WebContextFactory.get().getHttpServletRequest(); HttpServletResponse response = WebContextFactory.get().getHttpServletResponse(); Player player = getCurrentPlayer(request, response); Locale locale = settingsService.getLocale(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, locale); Date now = new Date(); Playlist playlist = new Playlist(); playlist.setUsername(securityService.getCurrentUsername(request)); playlist.setCreated(now);//from w w w . java 2 s .c o m playlist.setChanged(now); playlist.setPublic(false); playlist.setName(dateFormat.format(now)); playlistService.createPlaylist(playlist); playlistService.setFilesInPlaylist(playlist.getId(), player.getPlayQueue().getFiles()); return playlist.getName(); }
From source file:org.voidsink.anewjkuapp.utils.AppUtils.java
public static String getEventString(Context c, long eventDTStart, long eventDTEnd, String eventTitle, boolean allDay) { int index = eventTitle.indexOf(", "); if (index > 1) { eventTitle = eventTitle.substring(0, index); }/* w w w . ja v a2 s. co m*/ DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); return String.format("%s: %s, %s", df.format(eventDTStart), AppUtils.getTimeString(c, new Date(eventDTStart), new Date(eventDTEnd), allDay), eventTitle); }
From source file:org.waterforpeople.mapping.app.web.KMLGenerator.java
public String bindPlacemark(AccessPoint ap, String vmName, String display, StandardType standardType) throws Exception { // if (ap.getCountryCode() != null && !ap.getCountryCode().equals("MW")) // {//from w w w. j a v a2 s . com if (display != null && display.trim().equalsIgnoreCase(GOOGLE_EARTH_DISPLAY)) { vmName = "placemarkGoogleEarth.vm"; } if (ap.getCountryCode() == null) ap.setCountryCode("Unknown"); if (ap.getCountryCode() != null) { VelocityContext context = new VelocityContext(); context.put("organization", ORGANIZATION); if (display != null) { context.put("display", display); } context.put("countryCode", ap.getCountryCode()); if (ap.getCollectionDate() != null) { String timestamp = DateFormatUtils.formatUTC(ap.getCollectionDate(), DateFormatUtils.ISO_DATE_FORMAT.getPattern()); String formattedDate = DateFormat.getDateInstance(DateFormat.SHORT).format(ap.getCollectionDate()); context.put("collectionDate", formattedDate); context.put("timestamp", timestamp); String collectionYear = new SimpleDateFormat("yyyy").format(ap.getCollectionDate()); context.put("collectionYear", collectionYear); } else { String timestamp = DateFormatUtils.formatUTC(ap.getCreatedDateTime(), DateFormatUtils.ISO_DATE_FORMAT.getPattern()); String formattedDate = DateFormat.getDateInstance(DateFormat.SHORT).format(ap.getCreatedDateTime()); context.put("collectionDate", formattedDate); context.put("timestamp", timestamp); } if (ap.getCommunityCode() != null) context.put("communityCode", ap.getCommunityCode()); else context.put("communityCode", "Unknown" + new Date()); if (ap.getWaterForPeopleProjectFlag() != null) { context.put("waterForPeopleProject", encodeBooleanDisplay(ap.getWaterForPeopleProjectFlag())); } else { context.put("waterForPeopleProject", "null"); } if (ap.getCurrentProblem() != null) { context.put("currentProblem", ap.getCurrentProblem()); } else { context.put("currentProblem", ap.getCurrentProblem()); } if (ap.getWaterForPeopleRole() != null) { context.put("waterForPeopleRole", ap.getWaterForPeopleRole()); } else { context.put("waterForPeopleRole", "null"); } if (ap.getPhotoURL() != null && ap.getPhotoURL().trim() != "") context.put("photoUrl", ap.getPhotoURL()); else context.put("photoUrl", "http://waterforpeople.s3.amazonaws.com/images/wfplogo.jpg"); if (ap.getPointType() != null) { if (ap.getPointType().equals(AccessPoint.AccessPointType.WATER_POINT)) { context.put("typeOfPoint", "Water"); context.put("type", "water"); } else if (ap.getPointType().equals(AccessPointType.SANITATION_POINT)) { context.put("typeOfPoint", "Sanitation"); context.put("type", "sanitation"); } else if (ap.getPointType().equals(AccessPointType.PUBLIC_INSTITUTION)) { context.put("typeOfPoint", "Public Institutions"); context.put("type", "public_institutions"); } else if (ap.getPointType().equals(AccessPointType.HEALTH_POSTS)) { context.put("typeOfPoint", "Health Posts"); context.put("type", "health_posts"); } else if (ap.getPointType().equals(AccessPointType.SCHOOL)) { context.put("typeOfPoint", "School"); context.put("type", "school"); } } else { context.put("typeOfPoint", "Water"); context.put("type", "water"); } if (ap.getTypeTechnologyString() == null) { context.put("primaryTypeTechnology", "Unknown"); } else { context.put("primaryTypeTechnology", ap.getTypeTechnologyString()); } if (ap.getHasSystemBeenDown1DayFlag() == null) { context.put("down1DayFlag", "Unknown"); } else { context.put("down1DayFlag", encodeBooleanDisplay(ap.getHasSystemBeenDown1DayFlag())); } if (ap.getInstitutionName() == null) { context.put("institutionName", "Unknown"); } else { context.put("institutionName", ap.getInstitutionName()); } if (ap.getExtimatedPopulation() != null) { context.put("estimatedPopulation", ap.getExtimatedPopulation()); } else { context.put("estimatedPopulation", "null"); } if (ap.getConstructionDateYear() == null || ap.getConstructionDateYear().trim().equals("")) { context.put("constructionDateOfWaterPoint", "Unknown"); } else { String constructionDateYear = ap.getConstructionDateYear(); if (constructionDateYear.contains(".0")) { constructionDateYear = constructionDateYear.replace(".0", ""); } context.put("constructionDateOfWaterPoint", constructionDateYear); } if (ap.getNumberOfHouseholdsUsingPoint() != null) { context.put("numberOfHouseholdsUsingWaterPoint", ap.getNumberOfHouseholdsUsingPoint()); } else { context.put("numberOfHouseholdsUsingWaterPoint", "null"); } if (ap.getCostPer() == null) { context.put("costPer", "N/A"); } else { context.put("costPer", ap.getCostPer()); } if (ap.getFarthestHouseholdfromPoint() == null || ap.getFarthestHouseholdfromPoint().trim().equals("")) { context.put("farthestHouseholdfromWaterPoint", "N/A"); } else { context.put("farthestHouseholdfromWaterPoint", ap.getFarthestHouseholdfromPoint()); } if (ap.getCurrentManagementStructurePoint() == null) { context.put("currMgmtStructure", "N/A"); } else { context.put("currMgmtStructure", ap.getCurrentManagementStructurePoint()); } if (ap.getPointPhotoCaption() == null || ap.getPointPhotoCaption().trim().equals("")) { context.put("waterPointPhotoCaption", defaultPhotoCaption); } else { context.put("waterPointPhotoCaption", ap.getPointPhotoCaption()); } if (ap.getCommunityName() == null) { context.put("communityName", "Unknown"); } else { context.put("communityName", ap.getCommunityName()); } if (ap.getHeader() == null) { context.put("header", "Water For People"); } else { context.put("header", ap.getHeader()); } if (ap.getFooter() == null) { context.put("footer", "Water For People"); } else { context.put("footer", ap.getFooter()); } if (ap.getPhotoName() == null) { context.put("photoName", "Water For People"); } else { context.put("photoName", ap.getPhotoName()); } // if (ap.getCountryCode() == "RW") { if (ap.getMeetGovtQualityStandardFlag() == null) { context.put("meetGovtQualityStandardFlag", "N/A"); } else { context.put("meetGovtQualityStandardFlag", encodeBooleanDisplay(ap.getMeetGovtQualityStandardFlag())); } // } else { // context.put("meetGovtQualityStandardFlag", "unknown"); // } if (ap.getMeetGovtQuantityStandardFlag() == null) { context.put("meetGovtQuantityStandardFlag", "N/A"); } else { context.put("meetGovtQuantityStandardFlag", encodeBooleanDisplay(ap.getMeetGovtQuantityStandardFlag())); } if (ap.getWhoRepairsPoint() == null) { context.put("whoRepairsPoint", "N/A"); } else { context.put("whoRepairsPoint", ap.getWhoRepairsPoint()); } if (ap.getSecondaryTechnologyString() == null) { context.put("secondaryTypeTechnology", "N/A"); } else { context.put("secondaryTypeTechnology", ap.getSecondaryTechnologyString()); } if (ap.getProvideAdequateQuantity() == null) { context.put("provideAdequateQuantity", "N/A"); } else { context.put("provideAdequateQuantity", encodeBooleanDisplay(ap.getProvideAdequateQuantity())); } if (ap.getBalloonTitle() == null) { context.put("title", "Water For People"); } else { context.put("title", ap.getBalloonTitle()); } if (ap.getProvideAdequateQuantity() == null) { context.put("provideAdequateQuantity", "N/A"); } else { context.put("provideAdequateQuantity", encodeBooleanDisplay(ap.getProvideAdequateQuantity())); } if (ap.getQualityDescription() != null) { context.put("qualityDescription", ap.getQualityDescription()); } if (ap.getQuantityDescription() != null) { context.put("quantityDescription", ap.getQuantityDescription()); } if (ap.getSub1() != null) { context.put("sub1", ap.getSub1()); } if (ap.getSub2() != null) { context.put("sub2", ap.getSub2()); } if (ap.getSub3() != null) { context.put("sub3", ap.getSub3()); } if (ap.getSub4() != null) { context.put("sub4", ap.getSub4()); } if (ap.getSub5() != null) { context.put("sub5", ap.getSub5()); } if (ap.getSub6() != null) { context.put("sub6", ap.getSub6()); } if (ap.getAccessPointCode() != null) { context.put("accessPointCode", ap.getAccessPointCode()); } if (ap.getAccessPointUsage() != null) { context.put("accessPointUsage", ap.getAccessPointUsage()); } if (ap.getDescription() != null) context.put("description", ap.getDescription()); else context.put("description", "Unknown"); // Need to check this if (ap.getPointType() != null) { if (Boolean.parseBoolean(PropertyUtil.getProperty(DYNAMIC_SCORING_FLAG))) { TreeMap<String, String> combinedScore = fetchLevelOfServiceScoreStatus(ap); for (Map.Entry<String, String> entry : combinedScore.entrySet()) { context.put(entry.getKey(), entry.getValue()); String style = null; if (standardType != null) { if (standardType.equals(StandardType.WaterPointLevelOfService) && entry.getKey() .equals(StandardType.WaterPointLevelOfService.toString() + "-pinStyle")) { style = entry.getValue(); } else if (standardType.equals(StandardType.WaterPointSustainability) && entry.getKey() .equals(StandardType.WaterPointSustainability.toString() + "-pinStyle")) { style = entry.getValue(); } } context.put("pinStyle", style); } } else { encodeStatusString(ap, context); context.put("pinStyle", encodePinStyle(ap.getPointType(), ap.getPointStatus())); } } else { context.put("pinStyle", "waterpushpinblk"); } String output = mergeContext(context, vmName); context = null; return output; } return null; }
From source file:op.care.reports.PnlReport.java
private CollapsiblePane createCP4Week(final LocalDate week) { final String key = weekFormater.format(week.toDate()) + ".week"; synchronized (cpMap) { if (!cpMap.containsKey(key)) { cpMap.put(key, new CollapsiblePane()); try { cpMap.get(key).setCollapsed(true); } catch (PropertyVetoException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. }/*from w ww. j av a 2 s. c o m*/ } } final CollapsiblePane cpWeek = cpMap.get(key); String title = "<html><font size=+1><b>" + DateFormat.getDateInstance(DateFormat.SHORT).format(week.dayOfWeek().withMaximumValue().toDate()) + " - " + DateFormat.getDateInstance(DateFormat.SHORT).format(week.dayOfWeek().withMinimumValue().toDate()) + " (" + SYSTools.xx("misc.msg.weekinyear") + week.getWeekOfWeekyear() + ")" + "</b>" + "</font></html>"; DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { cpWeek.setCollapsed(!cpWeek.isCollapsed()); } catch (PropertyVetoException pve) { // BAH! } } }); GUITools.addExpandCollapseButtons(cpWeek, cptitle.getRight()); if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.PRINT, internalClassID)) { final JButton btnPrintWeek = new JButton(SYSConst.icon22print2); btnPrintWeek.setPressedIcon(SYSConst.icon22print2Pressed); btnPrintWeek.setAlignmentX(Component.RIGHT_ALIGNMENT); btnPrintWeek.setContentAreaFilled(false); btnPrintWeek.setBorder(null); btnPrintWeek.setToolTipText(SYSTools.xx("misc.tooltips.btnprintweek")); btnPrintWeek.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { SYSFilesTools.print(NReportTools.getNReportsAsHTML( NReportTools.getNReports4Week(resident, week), true, null, null), false); } }); cptitle.getRight().add(btnPrintWeek); } cpWeek.setTitleLabelComponent(cptitle.getMain()); cpWeek.setSlidingDirection(SwingConstants.SOUTH); cpWeek.setBackground(SYSConst.orange1[SYSConst.medium1]); cpWeek.setOpaque(false); cpWeek.setHorizontalAlignment(SwingConstants.LEADING); // cpMonth.setBackground(getColor(vtype, SYSConst.light3)); /*** * _ _ _ _ _ _ * ___| (_) ___| | _____ __| | ___ _ __ _ __ ___ ___ _ __ | |_| |__ * / __| | |/ __| |/ / _ \/ _` | / _ \| '_ \ | '_ ` _ \ / _ \| '_ \| __| '_ \ * | (__| | | (__| < __/ (_| | | (_) | | | | | | | | | | (_) | | | | |_| | | | * \___|_|_|\___|_|\_\___|\__,_| \___/|_| |_| |_| |_| |_|\___/|_| |_|\__|_| |_| * */ cpWeek.addCollapsiblePaneListener(new CollapsiblePaneAdapter() { @Override public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) { cpWeek.setContentPane(createContenPanel4Week(week)); } }); if (!cpWeek.isCollapsed()) { cpWeek.setContentPane(createContenPanel4Week(week)); } return cpWeek; }