List of usage examples for java.text DateFormat getDateInstance
public static final DateFormat getDateInstance(int style, Locale aLocale)
From source file:org.goobi.production.flow.statistics.StatisticsManager.java
/** * Calculate statistics and retrieve List off {@link DataRow} from * {@link StatisticsMode} for presentation and rendering. * *//*ww w . j av a 2 s . c o m*/ public void calculate() { /* * if to-date is before from-date, show error message */ if (sourceDateFrom != null && sourceDateTo != null && sourceDateFrom.after(sourceDateTo)) { Helper.setMeldung("myStatisticButton", "selectedDatesNotValide", "selectedDatesNotValide"); return; } /* * some debugging here */ if (logger.isDebugEnabled()) { logger.debug(sourceDateFrom + " - " + sourceDateTo + " - " + sourceNumberOfTimeUnits + " - " + sourceTimeUnit + "\n" + targetTimeUnit + " - " + targetCalculationUnit + " - " + targetResultOutput + " - " + showAverage); } /* * calculate the statistical results and save it as List of DataTables (because * some statistical questions allow multiple tables and charts) */ IStatisticalQuestion question = statisticMode.getStatisticalQuestion(); try { setTimeFrameToStatisticalQuestion(question); // picking up users input regarding loop Options if (isRenderLoopOption()) { try { ((StatQuestThroughput) question).setIncludeLoops(includeLoops); } catch (Exception e) { // just in case -> shouldn't happen logger.debug("unexpected Exception, wrong class loaded", e); } } if (targetTimeUnit != null) { question.setTimeUnit(targetTimeUnit); } if (targetCalculationUnit != null) { question.setCalculationUnit(targetCalculationUnit); } renderingElements = new ArrayList<>(); List<DataTable> myDataTables = question.getDataTables(dataSource); /* * if DataTables exist analyze them */ if (myDataTables != null) { /* * localize time frame for gui */ StringBuilder subname = new StringBuilder(); if (calculatedStartDate != null) { subname.append( DateFormat.getDateInstance(DateFormat.SHORT, myLocale).format(calculatedStartDate)); } subname.append(" - "); if (calculatedEndDate != null) { subname.append( DateFormat.getDateInstance(DateFormat.SHORT, myLocale).format(calculatedEndDate)); } if (calculatedStartDate == null && calculatedEndDate == null) { subname = new StringBuilder(); } /* * run through all DataTables */ for (DataTable dt : myDataTables) { dt.setSubname(subname.toString()); StatisticsRenderingElement sre = new StatisticsRenderingElement(dt, question); sre.createRenderer(showAverage); renderingElements.add(sre); } } } catch (UnsupportedOperationException e) { Helper.setFehlerMeldung("StatisticButton", "errorOccuredWhileCalculatingStatistics", e); } }
From source file:org.openmrs.web.WebUtil.java
public static String formatDate(Date date, Locale locale, FORMAT_TYPE type) { log.debug("Formatting date: " + date + " with locale " + locale); DateFormat dateFormat = null; if (type == FORMAT_TYPE.TIMESTAMP) { String dateTimeFormat = Context.getAdministrationService() .getGlobalPropertyValue(OpenmrsConstants.GP_SEARCH_DATE_DISPLAY_FORMAT, null); if (StringUtils.isEmpty(dateTimeFormat)) { dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); } else {/* w w w . ja v a2s .c o m*/ dateFormat = new OpenmrsDateFormat(new SimpleDateFormat(dateTimeFormat), locale); } } else if (type == FORMAT_TYPE.TIME) { String timeFormat = Context.getAdministrationService() .getGlobalPropertyValue(OpenmrsConstants.GP_SEARCH_DATE_DISPLAY_FORMAT, null); if (StringUtils.isEmpty(timeFormat)) { dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale); } else { dateFormat = new OpenmrsDateFormat(new SimpleDateFormat(timeFormat), locale); } } else if (type == FORMAT_TYPE.DATE) { String formatValue = Context.getAdministrationService() .getGlobalPropertyValue(OpenmrsConstants.GP_SEARCH_DATE_DISPLAY_FORMAT, ""); if (StringUtils.isEmpty(formatValue)) { dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale); } else { dateFormat = new OpenmrsDateFormat(new SimpleDateFormat(formatValue), locale); } } return date == null ? "" : dateFormat.format(date); }
From source file:org.hoteia.qalingo.core.service.EmailService.java
/** * @throws Exception /*from w ww . ja va2 s .c o m*/ */ public Email buildAndSaveAdminNotification(final RequestData requestData, final String velocityPath, final AdminNotificationEmailBean adminNotificationEmailBean) throws Exception { Email email = null; try { final String contextNameValue = requestData.getContextNameValue(); final Localization localization = requestData.getMarketAreaLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(adminNotificationEmailBean); Map<String, Object> model = new HashMap<String, Object>(); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale); java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime()); model.put(CURRENT_DATE, dateFormatter.format(currentDate)); model.put("adminNotificationEmailBean", adminNotificationEmailBean); model.put(WORDING, coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); String fromAddress = handleFromAddress(adminNotificationEmailBean.getFromAddress(), contextNameValue); String fromName = handleFromName(adminNotificationEmailBean.getFromName(), locale); String toEmail = adminNotificationEmailBean.getToEmail(); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_ADMIN_NOTIFICATION, model); mimeMessagePreparator.setTo(toEmail); mimeMessagePreparator.setFrom(fromAddress); mimeMessagePreparator.setFromName(fromName); mimeMessagePreparator.setReplyTo(fromAddress); mimeMessagePreparator.setSubject(adminNotificationEmailBean.getSubject()); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(getVelocityEngine(), velocityPath + "admin-notification-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString( getVelocityEngine(), velocityPath + "admin-notification-text-content.vm", model)); email = new Email(); email.setType(Email.EMAIl_TYPE_ADMIN_NOTIFICATION); email.setStatus(Email.EMAIl_STATUS_PENDING); saveOrUpdateEmail(email, mimeMessagePreparator); } catch (MailException e) { logger.error("Error, can't save the message :", e); throw e; } catch (VelocityException e) { logger.error("Error, can't build the message :", e); throw e; } catch (IOException e) { logger.error("Error, can't serializable the message :", e); throw e; } return email; }
From source file:org.mifos.framework.util.helpers.DateUtils.java
public static String getCurrentDate() throws InvalidDateException { Calendar currentCalendar = getCurrentDateCalendar(); java.sql.Date currentDate = new java.sql.Date(currentCalendar.getTimeInMillis()); SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, internalLocale); String userfmt = convertToCurrentDateFormat(format.toPattern()); return convertDbToUserFmt(currentDate.toString(), userfmt); }
From source file:org.apache.cocoon.generation.CalendarGenerator.java
/** * Set the request parameters. Must be called before the generate method. * * @param resolver the SourceResolver object * @param objectModel a <code>Map</code> containing model object * @param src the source URI (ignored) * @param par configuration parameters *//* w w w . ja v a 2 s .c om*/ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException { super.setup(resolver, objectModel, src, par); this.cacheKeyParList = new ArrayList(); this.cacheKeyParList.add(src); // Determine the locale String langString = par.getParameter("lang", null); locale = Locale.getDefault(); if (langString != null) { this.cacheKeyParList.add(langString); String countryString = par.getParameter("country", ""); if (!"".equals(countryString)) { this.cacheKeyParList.add(countryString); } locale = new Locale(langString, countryString); } // Determine year and month. Default is current year and month. Calendar now = Calendar.getInstance(locale); this.year = par.getParameterAsInteger("year", now.get(Calendar.YEAR)); this.cacheKeyParList.add(String.valueOf(this.year)); this.month = par.getParameterAsInteger("month", now.get(Calendar.MONTH) + 1) - 1; this.cacheKeyParList.add(String.valueOf(this.month)); String dateFormatString = par.getParameter("dateFormat", null); this.cacheKeyParList.add(dateFormatString); if (dateFormatString != null) { this.dateFormatter = new SimpleDateFormat(dateFormatString, locale); } else { this.dateFormatter = DateFormat.getDateInstance(DateFormat.LONG, locale); } this.padWeeks = par.getParameterAsBoolean("padWeeks", false); this.cacheKeyParList.add(BooleanUtils.toBooleanObject(this.padWeeks)); this.monthFormatter = new SimpleDateFormat("MMMM", locale); this.attributes = new AttributesImpl(); }
From source file:com.itude.mobile.mobbl.core.util.StringUtilities.java
public static String formatDateDependingOnCurrentDate(String dateString) { if (isEmpty(dateString)) { return ""; }/*ww w .j av a 2s. co m*/ String result = dateString; Date date = dateFromXML(dateString); DateFormat df; // We can't just compare two dates, because the time is also compared. // Therefore the time is removed and the two dates without time are compared Calendar calendar = Calendar.getInstance(); calendar.setTime(date); Calendar today = Calendar.getInstance(); today.setTime(new Date()); if (calendar.get(Calendar.YEAR) == today.get(Calendar.YEAR) && calendar.get(Calendar.MONTH) == today.get(Calendar.MONTH) && calendar.get(Calendar.DAY_OF_YEAR) == today.get(Calendar.DAY_OF_YEAR)) { df = new SimpleDateFormat("HH:mm:ss"); } else { df = DateFormat.getDateInstance(DateFormat.SHORT, getDefaultFormattingLocale() != null ? getDefaultFormattingLocale() : Locale.getDefault()); } // Format the date try { result = df.format(date); return result; } catch (Exception e) { throw new MBDateParsingException( "Could not get format date depending on current date with input string: " + dateString, e); } }
From source file:org.jivesoftware.util.JiveGlobals.java
/** * Formats a Date object to return a date using the global locale. * * @param date the Date to format./* w ww . j a v a 2 s . c o m*/ * @return a String representing the date. */ public static String formatDate(Date date) { if (dateFormat == null) { if (properties != null) { dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale()); dateFormat.setTimeZone(getTimeZone()); } else { DateFormat instance = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale()); instance.setTimeZone(getTimeZone()); return instance.format(date); } } return dateFormat.format(date); }
From source file:fr.hoteia.qalingo.core.service.impl.EmailServiceImpl.java
/** * @see fr.hoteia.qalingo.core.service.EmailService#buildAndSaveRetailerContactMail(Localization localization, Customer customer, String velocityPath, RetailerContactEmailBean retailerContactEmailBean) */// ww w . j a v a 2 s. c o m public void buildAndSaveRetailerContactMail(final RequestData requestData, final Customer customer, final String velocityPath, final RetailerContactEmailBean retailerContactEmailBean) throws Exception { try { final Localization localization = requestData.getLocalization(); final Locale locale = localization.getLocale(); // SANITY CHECK checkEmailAddresses(retailerContactEmailBean); Map<String, Object> model = new HashMap<String, Object>(); String fromEmail = retailerContactEmailBean.getFromEmail(); String toEmail = retailerContactEmailBean.getToEmail(); DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.FULL, locale); java.sql.Timestamp currentDate = new java.sql.Timestamp((new java.util.Date()).getTime()); model.put("currentDate", dateFormatter.format(currentDate)); model.put("customer", customer); model.put("retailerContactEmailBean", retailerContactEmailBean); model.put("wording", coreMessageSource.loadWording(Email.WORDING_SCOPE_EMAIL, locale)); MimeMessagePreparatorImpl mimeMessagePreparator = getMimeMessagePreparator(requestData, Email.EMAIl_TYPE_RETAILER_CONTACT, model); mimeMessagePreparator.setTo(toEmail); mimeMessagePreparator.setFrom(fromEmail); mimeMessagePreparator.setFromName(coreMessageSource.getMessage("email.common.from_name", locale)); mimeMessagePreparator.setReplyTo(fromEmail); Object[] parameters = { retailerContactEmailBean.getLastname(), retailerContactEmailBean.getFirstname() }; mimeMessagePreparator.setSubject( coreMessageSource.getMessage("email.retailer_contact.email_subject", parameters, locale)); mimeMessagePreparator.setHtmlContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "retailer-contact-html-content.vm", model)); mimeMessagePreparator.setPlainTextContent(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityPath + "retailer-contact-text-content.vm", model)); Email email = new Email(); email.setType(Email.EMAIl_TYPE_RETAILER_CONTACT); email.setStatus(Email.EMAIl_STATUS_PENDING); saveOrUpdateEmail(email, mimeMessagePreparator); } catch (MailException e) { LOG.error("Error, can't save the message :", e); throw e; } catch (VelocityException e) { LOG.error("Error, can't build the message :", e); throw e; } catch (IOException e) { LOG.error("Error, can't serializable the message :", e); throw e; } }
From source file:com.miz.mizuu.fragments.ShowEpisodeDetailsFragment.java
public void onViewCreated(View v, Bundle savedInstanceState) { super.onViewCreated(v, savedInstanceState); if (thisEpisode != null) { cover = (ImageView) v.findViewById(R.id.traktIcon); playbutton = (ImageView) v.findViewById(R.id.imageView2); title = (TextView) v.findViewById(R.id.overviewMessage); plot = (TextView) v.findViewById(R.id.textView2); airdate = (TextView) v.findViewById(R.id.textView9); rating = (TextView) v.findViewById(R.id.textView11); director = (TextView) v.findViewById(R.id.textView7); writer = (TextView) v.findViewById(R.id.textView3); gueststars = (TextView) v.findViewById(R.id.TextView04); file = (TextView) v.findViewById(R.id.TextView07); // Set the episode details title.setText(thisEpisode.getTitle()); title.setTypeface(tf);//from ww w.j a va2 s. c om if (MizLib.isGoogleTV(getActivity())) title.setTextSize(28f); title.setLayerType(View.LAYER_TYPE_SOFTWARE, null); if (!thisEpisode.getDescription().equals(getString(R.string.stringNA)) && !MizLib.isEmpty(thisEpisode.getDescription())) plot.setText(thisEpisode.getDescription()); else plot.setText(getString(R.string.stringNoPlot)); if (MizLib.isEmpty(thisEpisode.getReleasedate()) || thisEpisode.getReleasedate().equals(getString(R.string.stringNA))) { v.findViewById(R.id.tableRow1).setVisibility(View.GONE); } else { // Set the genre first aired date try { String[] date = thisEpisode.getReleasedate().split("-"); Calendar cal = Calendar.getInstance(); cal.set(Integer.parseInt(date[0]), Integer.parseInt(date[1]) - 1, Integer.parseInt(date[2])); airdate.setText(DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()) .format(cal.getTime())); } catch (Exception e) { // Fall back if something goes wrong airdate.setText(thisEpisode.getReleasedate()); } } if (!thisEpisode.getRating().equals("0/10")) rating.setText(thisEpisode.getRating()); else v.findViewById(R.id.tableRow2).setVisibility(View.GONE); if (MizLib.isEmpty(thisEpisode.getDirector()) || thisEpisode.getDirector().equals(getString(R.string.stringNA))) { v.findViewById(R.id.tableRow3).setVisibility(View.GONE); } else { director.setText(thisEpisode.getDirector()); } if (MizLib.isEmpty(thisEpisode.getWriter()) || thisEpisode.getWriter().equals(getString(R.string.stringNA))) { v.findViewById(R.id.tableRow4).setVisibility(View.GONE); } else { writer.setText(thisEpisode.getWriter()); } if (MizLib.isEmpty(thisEpisode.getGuestStars()) || thisEpisode.getGuestStars().equals(getString(R.string.stringNA))) { v.findViewById(R.id.tableRow5).setVisibility(View.GONE); } else { gueststars.setText(thisEpisode.getGuestStars()); } file.setText(thisEpisode.getFilepath()); playbutton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { play(); } }); mPicasso.load(thisEpisode.getEpisodePhoto()).skipMemoryCache().placeholder(R.drawable.bg).into(cover, new Callback() { @Override public void onError() { if (isAdded()) mPicasso.load(MizLib.getTvShowThumbFolder(getActivity()) + "/" + thisEpisode.getShowId() + ".jpg").skipMemoryCache() .placeholder(R.drawable.bg).error(R.drawable.nobackdrop).into(cover); } @Override public void onSuccess() { } }); } }
From source file:net.joinedminds.masserr.Functions.java
public static String formatDate(Date dateTime) { StaplerRequest request = Stapler.getCurrentRequest(); DateFormat format;//from www. j a v a 2 s . co m if (request != null) { format = DateFormat.getDateInstance(DateFormat.MEDIUM, request.getLocale()); } else { format = DateFormat.getDateInstance(DateFormat.MEDIUM); } return format.format(dateTime); }