List of usage examples for java.text DateFormat getDateInstance
public static final DateFormat getDateInstance(int style)
From source file:edu.ku.brc.util.DateConverter.java
/** * //from w ww. j a va2 s. c o m */ public DateConverter() { String currentFormat = AppPreferences.getRemote().get("ui.formatting.scrdateformat", null); if (currentFormat.startsWith("MM") || currentFormat.startsWith("mm")) { preferMonthDay = true; } else if (currentFormat.startsWith("DD") || currentFormat.startsWith("dd")) { preferMonthDay = false; } else { DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); //for default locale; SHORT -> completely numeric Calendar result = new GregorianCalendar(); result.set(2000, 3, 1); String dtstr = df.format(result.getTime()); int moIdx = dtstr.indexOf("4"); int dayIdx = dtstr.indexOf("1"); preferMonthDay = moIdx < dayIdx; } //System.out.println(df.) //preferMonthDay = /*loc == Locale.CANADA || */loc == Locale.US; }
From source file:org.openehealth.pors.core.PorsCoreBean.java
/** * @see IPorsCore#assembleDuplicateEntryDTO(DuplicateEntry) *//*from ww w . j ava 2 s . co m*/ public DuplicateEntryDTO assembleDuplicateEntryDTO(DuplicateEntry duplicate) { DuplicateEntryDTO duplicateDTO = new DuplicateEntryDTO(); duplicateDTO.setDomain(duplicate.getId().getDomain()); duplicateDTO.setLogTime(duplicate.getTimestamp()); duplicateDTO .setLogDateString(DateFormat.getDateInstance(DateFormat.MEDIUM).format(duplicate.getTimestamp())); DateFormat dfmt = new SimpleDateFormat("HH:mm:ss:SS"); duplicateDTO.setLogTimeString(dfmt.format(duplicate.getTimestamp())); NumberFormat formatter = new DecimalFormat("#0.00"); duplicateDTO.setPercentage(formatter.format(duplicate.getValue() * 100.0)); duplicateDTO.setId1(duplicate.getId().getId1()); duplicateDTO.setId2(duplicate.getId().getId2()); return duplicateDTO; }
From source file:org.squale.squalecommon.enterpriselayer.facade.quality.MeasureFacade.java
/** * Creation d'une mesure de type Kiviat pour un projet * //w ww . ja va 2 s .c o m * @param pProjectId Id du projet * @param pAuditId Id de l'audit * @param pAllFactors tous les facteurs (= "true") ou seulement ceux ayant une note ? * @throws JrafEnterpriseException en cas de pb Hibernate * @return tableau d'objets : la map des donnes + le boolen pour affichage de la case cocher tous les facteurs */ public static Object[] getProjectKiviat(Long pProjectId, Long pAuditId, String pAllFactors) throws JrafEnterpriseException { Map result = new HashMap(); JFreeChart projectKiviat = null; MeasureDAOImpl measureDAO = MeasureDAOImpl.getInstance(); // Session Hibernate ISession session = null; // Boolen conditonnanant l'affichage de la case cocher "tous les facteurs" dans la page Jsp boolean displayCheckBoxFactors = true; try { // rcupration d'une session session = PERSISTENTPROVIDER.getSession(); // On ajoute les notes de chaque projets sur le kiviat ProjectBO project = (ProjectBO) ProjectDAOImpl.getInstance().load(session, pProjectId); SortedMap values = new TreeMap(); // recupere les facteurs du projet Collection factorResults = QualityResultDAOImpl.getInstance().findWhere(session, pProjectId, pAuditId); // et cree le map nom => note correspondant Iterator it = factorResults.iterator(); ArrayList nullValuesList = new ArrayList(); while (it.hasNext()) { FactorResultBO factor = (FactorResultBO) it.next(); // le -1 est trait directement par le kiviatMaker Float value = new Float(factor.getMeanMark()); // ajoute la note dans le titre // TODO prendre le vritable nom du facteur String name = factor.getRule().getName(); if (value.floatValue() >= 0) { // avec 1 seul chiffre aprs la virgule NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(1); nf.setMaximumFractionDigits(1); name = name + " (" + nf.format(value) + ")"; } else { // Mmorisation temporaire des facteurs pour lesquels les notes sont nulles : sera utile si l'option // "Tous les facteurs" est coche pour afficher uniquement les facteurs ayant une note. nullValuesList.add(name); } values.put(name, value); } final int FACTORS_MIN = 3; if (nullValuesList.size() <= 0 || values.size() <= FACTORS_MIN) { displayCheckBoxFactors = false; } // Seulement les facteurs ayant une note ? ==> suppression des facteurs ayant une note nulle. // Mais trois facteurs doivent au moins s'afficher (nuls ou pas !) values = deleteFactors(values, nullValuesList, pAllFactors, FACTORS_MIN); // recupre le nom de l'audit String name = null; AuditBO audit = (AuditBO) AuditDAOImpl.getInstance().load(session, pAuditId); if (audit.getType().compareTo(AuditBO.MILESTONE) == 0) { name = audit.getName(); } if (null == name) { DateFormat df = DateFormat.getDateInstance(DateFormat.LONG); name = df.format(audit.getDate()); } result.put(name, values); } catch (Exception e) { FacadeHelper.convertException(e, MeasureFacade.class.getName() + ".getMeasures"); } finally { FacadeHelper.closeSession(session, MeasureFacade.class.getName() + ".getMeasures"); } Object[] kiviatObject = { result, new Boolean(displayCheckBoxFactors) }; return kiviatObject; }
From source file:ca.uvic.cs.tagsea.statistics.svn.jobs.SVNCommentScanningJob.java
private String getDateString() { Date d = new Date(System.currentTimeMillis()); DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT); String key = format.format(d); key = key.replace('/', '-'); key = key.replace('\\', '\\'); key = key.replace(' ', '_'); key = key.replace(':', '_'); key = key.replace(';', '.'); return key;//from w w w . j a v a 2 s . c o m }
From source file:org.gnenc.yams.portlet.AccountManagement.java
public void removeAccountOnSchedule(ActionRequest actionRequest, ActionResponse actionResponse) { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); Account callingAccount = null;// w w w. j a v a2 s .co m try { callingAccount = ActionUtil.accountFromEmailAddress(themeDisplay.getUser().getEmailAddress()); } catch (Exception e1) { e1.printStackTrace(); } String jspPage = null; String backURL = DAOParamUtil.getString(actionRequest, "backURL"); String dateString = DAOParamUtil.getString(actionRequest, "remove-date"); Date date = null; Date noticeDate = null; DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM); try { date = new SimpleDateFormat("MM/dd/yy").parse(dateString); Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DATE, -6); noticeDate = cal.getTime(); } catch (ParseException e1) { SessionErrors.add(actionRequest, "remove-account-failed"); jspPage = PortletUtil.ACCT_MGMT_ACCOUNT_REMOVE_JSP; } Account account = ActionUtil.accountFromUidNumber(DAOParamUtil.getString(actionRequest, "uidNumber")); actionResponse.setRenderParameter("uidNumber", account.getAttribute("uidNumber")); actionResponse.setRenderParameter("backURL", backURL); if (PermissionsChecker.hasPermission(callingAccount, account, PermissionsChecker.PERMISSION_ACCOUNT_REMOVE)) { try { // Send email 7 days before removal JobQueueLocalServiceUtil.addJob(themeDisplay.getUserId(), account.getMail().get(0), account.getDisplayName(), "Scheduled removal of " + account.getMail().get(0), PortletUtil.JOB_ACTION_REMOVE_EMAIL_NOTICE, noticeDate); // Remove the account on the date JobQueueLocalServiceUtil.addJob(themeDisplay.getUserId(), account.getMail().get(0), account.getDisplayName(), "Scheduled removal of " + account.getMail().get(0), PortletUtil.JOB_ACTION_REMOVE, date); // Send an email immediately MailEngine.send(PropsValues.JOB_FROM_EMAIL_ADDRESS, account.getMail().get(0), PropsValues.JOB_REMOVE_NOTICE_EMAIL_SUBJECT, PropsValues.JOB_REMOVE_NOTICE_EMAIL_BODY + "\n\nRemoval date: " + df.format(date)); } catch (Exception e) { SessionErrors.add(actionRequest, "remove-account-failed"); e.printStackTrace(); jspPage = PortletUtil.ACCT_MGMT_ACCOUNT_REMOVE_JSP; } jspPage = PortletUtil.SEARCH_VIEW_JSP; } else { SessionErrors.add(actionRequest, "insufficient-privileges"); jspPage = PortletUtil.ACCT_MGMT_ACCOUNT_REMOVE_JSP; } writeActionLog(actionRequest, account.getMail().get(0), account.getDisplayName(), account.getAttribute("esuccEntity"), "Scheduled account removal for " + df.format(date)); actionResponse.setRenderParameter("jspPage", jspPage); }
From source file:com.markuspage.android.atimetracker.Tasks.java
private void switchView(int which) { Calendar tw = Calendar.getInstance(); int startDay = preferences.getInt(START_DAY, 0) + 1; tw.setFirstDayOfWeek(startDay);/*from ww w .ja va2s . c o m*/ String ttl = getString(R.string.title, getResources().getStringArray(R.array.views)[which]); switch (which) { case 0: // today adapter.loadTasks(tw); break; case 1: // this week adapter.loadTasks(weekStart(tw, startDay), weekEnd(tw, startDay)); break; case 2: // yesterday tw.add(Calendar.DAY_OF_MONTH, -1); adapter.loadTasks(tw); break; case 3: // last week tw.add(Calendar.WEEK_OF_YEAR, -1); adapter.loadTasks(weekStart(tw, startDay), weekEnd(tw, startDay)); break; case 4: // all adapter.loadTasks(); break; case 5: // select range Calendar start = Calendar.getInstance(); start.setTimeInMillis(preferences.getLong(START_DATE, 0)); System.err.println("START = " + start.getTime()); Calendar end = Calendar.getInstance(); end.setTimeInMillis(preferences.getLong(END_DATE, 0)); System.err.println("END = " + end.getTime()); adapter.loadTasks(start, end); DateFormat f = DateFormat.getDateInstance(DateFormat.SHORT); ttl = getString(R.string.title, f.format(start.getTime()) + " - " + f.format(end.getTime())); break; default: // Unknown break; } baseTitle = ttl; setTitle(); getListView().invalidate(); }
From source file:DDTDate.java
/** * Creates the output the user indicated in the input (outputType component) subject to the requested style (outputStyle) component * @return/*ww w . j a v a 2 s . c o m*/ */ private String createOutput() { String result = ""; try { // If needed, adjust the reference date by the number and type of units specified - as per the time zone if (getUnits() != 0) { //setReferenceDate(getReferenceDateAdjustedForTimeZone()); getReferenceDate().add(getDurationType(), getUnits()); } // Create date formatters to be used for all varieties - the corresponding date variables are always set for convenience purposes DateFormat shortFormatter = DateFormat.getDateInstance(DateFormat.SHORT); DateFormat mediumFormatter = DateFormat.getDateInstance(DateFormat.MEDIUM); DateFormat longFormatter = DateFormat.getDateInstance(DateFormat.LONG); DateFormat fullFormatter = DateFormat.getDateInstance(DateFormat.FULL); // Build the specific formatter specified DateFormat formatter = null; switch (getOutputStyle().toLowerCase()) { case "medium": { formatter = mediumFormatter; break; } case "long": { formatter = longFormatter; break; } case "full": { formatter = fullFormatter; break; } default: formatter = shortFormatter; } // output style switch // construct the specified result - one at a time MutableDateTime theReferenceDate = getReferenceDate(); //getReferenceDateAdjustedForTimeZone(); switch (getOutputType().toLowerCase()) { case "date": { result = formatter.format(theReferenceDate.toDate()); break; } case "time": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("hh:mm:ss"); break; } default: result = theReferenceDate.toString("hh:mm:ss.SSS"); } break; } // separate time components case "hour": case "minute": case "second": case "hour24": { String tmp = theReferenceDate.toString("hh:mm:ss"); if (tmp.toString().contains(":")) { String[] hms = split(tmp.toString(), ":"); if (hms.length > 2) { switch (getOutputType().toLowerCase()) { case "hour": { // Hour - '12' result = hms[0]; break; } case "minute": { // Minutes - '34' result = hms[1]; break; } case "second": { // Second - '56' result = hms[2]; break; } case "hour24": { // Hour - '23' result = theReferenceDate.toString("HH"); break; } default: result = hms[0]; } // switch for individual time component } // three parts of time components } // timestamp contains separator ":" break; } // Hours, Minutes, Seconds case "year": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("yy"); break; } default: result = theReferenceDate.toString("yyyy"); } break; } case "month": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("M"); break; } case "medium": { // padded with 0 result = theReferenceDate.toString("MM"); break; } case "long": { // short name 'Feb' result = theReferenceDate.toString("MMM"); break; } default: // Full name 'September' result = theReferenceDate.toString("MMMM"); } break; } case "day": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("d"); break; } case "medium": { result = theReferenceDate.toString("dd"); break; } default: result = theReferenceDate.toString("dd"); } } case "doy": { result = theReferenceDate.toString("D"); break; } case "dow": { switch (getOutputStyle().toLowerCase()) { case "short": { result = theReferenceDate.toString("E"); break; } case "medium": { DateTime dt = new DateTime(theReferenceDate.toDate()); DateTime.Property dowDTP = dt.dayOfWeek(); result = dowDTP.getAsText(); break; } default: result = theReferenceDate.toString("E"); } break; } // day of week case "zone": { result = theReferenceDate.toString("zzz"); break; } case "era": { result = theReferenceDate.toString("G"); break; } case "ampm": { result = theReferenceDate.toString("a"); break; } default: { setException("Invalid Output Unit - cannot set output"); } // Create full date variables for the short, medium, long, full styles } // output type switch } // try constructing result catch (Exception e) { setException(e); } finally { return result; } }
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 w w. ja va 2s .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; }
From source file:org.openmrs.web.controller.person.PersonFormController.java
/** * Add the given name, gender, and birthdate/age to the given Person * /*from ww w .j ava2 s. c om*/ * @param <P> Should be a Patient or User object * @param person * @param name * @param gender * @param date birthdate * @param age */ public static <P extends Person> void getMiniPerson(P person, String name, String gender, String date, String age) { person.addName(Context.getPersonService().parsePersonName(name)); person.setGender(gender); Date birthdate = null; boolean birthdateEstimated = false; if (StringUtils.isNotEmpty(date)) { try { // only a year was passed as parameter if (date.length() < 5) { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, Integer.valueOf(date)); c.set(Calendar.MONTH, 0); c.set(Calendar.DATE, 1); birthdate = c.getTime(); birthdateEstimated = true; } // a full birthdate was passed as a parameter else { birthdate = Context.getDateFormat().parse(date); birthdateEstimated = false; } } catch (ParseException e) { log.debug("Error getting date from birthdate", e); } } else if (age != null && !"".equals(age)) { Calendar c = Calendar.getInstance(); c.setTime(new Date()); Integer d = c.get(Calendar.YEAR); d = d - Integer.parseInt(age); try { birthdate = DateFormat.getDateInstance(DateFormat.SHORT).parse("01/01/" + d); birthdateEstimated = true; } catch (ParseException e) { log.debug("Error getting date from age", e); } } if (birthdate != null) { person.setBirthdate(birthdate); } person.setBirthdateEstimated(birthdateEstimated); }
From source file:ca.oson.json.Oson.java
public Oson setDateFormat(int style) { options.setDateFormat(DateFormat.getDateInstance(style)); reset(); return this; }