List of usage examples for java.text DateFormat getDateInstance
public static final DateFormat getDateInstance(int style)
From source file:org.kuali.kra.irb.protocol.reference.ProtocolReference.java
private Date convertStringToDate(String stringDate) throws ParseException { if (!StringUtils.isBlank(stringDate)) { Date date = new Date(DateFormat.getDateInstance(DateFormat.SHORT).parse(stringDate).getTime()); return date; } else {/*from w w w . j a va2s. c om*/ return null; } }
From source file:org.openvpms.report.openoffice.OpenOfficeIMReportTestCase.java
/** * Tests reporting./*from w ww .j av a 2 s . co m*/ * * @throws IOException for any I/O error */ @Test public void testReport() throws IOException { Document doc = getDocument("src/test/reports/act.customerEstimation.odt", DocFormats.ODT_TYPE); Functions functions = applicationContext.getBean(Functions.class); IMReport<IMObject> report = new OpenOfficeIMReport<IMObject>(doc, getArchetypeService(), getLookupService(), getHandlers(), functions); Map<String, Object> fields = new HashMap<String, Object>(); Party practice = (Party) create(PracticeArchetypes.PRACTICE); practice.setName("Vets R Us"); fields.put("OpenVPMS.practice", practice); Party party = createCustomer(); ActBean act = createAct("act.customerEstimation"); Date startTime = Date.valueOf("2006-08-04"); act.setValue("startTime", startTime); act.setValue("lowTotal", new BigDecimal("100")); act.setParticipant("participation.customer", party); List<IMObject> objects = Arrays.asList((IMObject) act.getAct()); Document result = report.generate(objects, null, fields, DocFormats.ODT_TYPE); Map<String, String> userFields = getUserFields(result); String expectedStartTime = DateFormat.getDateInstance(DateFormat.MEDIUM).format(startTime); assertEquals(expectedStartTime, userFields.get("startTime")); assertEquals("$100.00", userFields.get("lowTotal")); assertEquals("J", userFields.get("firstName")); assertEquals("Zoo", userFields.get("lastName")); assertEquals("2.00", userFields.get("expression")); assertEquals("1234 Foo St\nMelbourne VIC 3001", userFields.get("address")); assertEquals("Vets R Us", userFields.get("practiceName")); assertEquals("Invalid property name: invalid", userFields.get("invalid")); }
From source file:org.kuali.kra.irb.protocol.reference.ProtocolReferenceRule.java
private boolean validateDate(String stringDate) { try {/*from w w w. ja va 2 s . c om*/ if (!StringUtils.isBlank(stringDate)) { Date date = new Date(DateFormat.getDateInstance(DateFormat.SHORT).parse(stringDate).getTime()); } } catch (ParseException e) { return false; } return true; }
From source file:ca.uvic.cs.tagsea.wizards.TagNetworkSender.java
private static String getToday() { Date today = new Date(System.currentTimeMillis()); String todayString = DateFormat.getDateInstance(DateFormat.SHORT).format(today); todayString = todayString.replace('/', '_'); todayString = todayString.replace('\\', '-'); todayString = todayString.replace('.', '_'); todayString = todayString.replace(':', '_'); todayString = todayString.replace(';', '_'); return todayString; }
From source file:org.ambraproject.annotation.action.GetAnnotationAction.java
/** * Returns Milliseconds representation of the CIS start date * @return Milliseconds representation of the CIS start date * @throws Exception on bad config data or config entry not found. *///ww w. ja v a 2 s. c o m public long getCisStartDateMillis() throws Exception { try { return DateFormat.getDateInstance(DateFormat.SHORT) .parse(this.configuration.getString("ambra.platform.cisStartDate")).getTime(); } catch (ParseException ex) { throw (Exception) new Exception( "Could not find or parse the cisStartDate node in the ambra platform configuration. Make sure the ambra/platform/cisStartDate node exists.") .initCause(ex); } }
From source file:net.sourceforge.processdash.ui.web.reports.XYChart.java
/** Create a scatter plot. */ @Override/*from w w w . j ava 2 s . c om*/ public JFreeChart createChart() { JFreeChart chart; String xLabel = null, yLabel = null; if (!chromeless) { xLabel = Translator.translate(data.getColName(1)); yLabel = getSetting("yLabel"); if (yLabel == null && data.numCols() == 2) yLabel = data.getColName(2); if (yLabel == null) yLabel = getSetting("units"); if (yLabel == null) yLabel = "Value"; yLabel = Translator.translate(yLabel); } Object autoZero = parameters.get("autoZero"); boolean firstColumnContainsDate = data.numRows() > 0 && data.numCols() > 0 && data.getData(1, 1) instanceof DateData; if (firstColumnContainsDate || parameters.get("xDate") != null) { chart = ChartFactory.createTimeSeriesChart(null, xLabel, yLabel, data.xyDataSource(), true, true, false); if (firstColumnContainsDate && ((DateData) data.getData(1, 1)).isFormatAsDateOnly()) chart.getXYPlot().getRenderer().setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, DateFormat.getDateInstance(DateFormat.SHORT), NumberFormat.getInstance())); } else { XYDataset src = data.xyDataSource(); chart = ChartFactory.createScatterPlot(null, xLabel, yLabel, src, PlotOrientation.VERTICAL, true, true, false); if (src instanceof XYToolTipGenerator) { chart.getXYPlot().getRenderer().setBaseToolTipGenerator((XYToolTipGenerator) src); } String trendLine = getParameter("trend"); if ("none".equalsIgnoreCase(trendLine)) ; else if ("average".equalsIgnoreCase(trendLine)) addTrendLine(chart, XYDataSourceTrendLine.getAverageLine(src, 0, autoZero != null && !autoZero.equals("y"))); else addTrendLine(chart, XYDataSourceTrendLine.getRegressionLine(src, 0, autoZero != null && !autoZero.equals("y"))); } if (autoZero != null) { if (!"x".equals(autoZero)) ((NumberAxis) chart.getXYPlot().getRangeAxis()).setAutoRangeIncludesZero(true); if (!"y".equals(autoZero)) ((NumberAxis) chart.getXYPlot().getDomainAxis()).setAutoRangeIncludesZero(true); } if (data.numCols() == 2) chart.removeLegend(); return chart; }
From source file:org.codekaizen.vtj.text.BpDateFormatTest.java
/** * DOCUMENT ME!/*from ww w .j a va 2 s . com*/ */ public void testFormatting() { DateFormat fmt1 = null; DateFormat fmt2 = null; Date date = null; String s1 = null; String s2 = null; date = new Date(); fmt1 = new BpDateFormat(BpDateFormat.JVM_DATE_TIME, null); fmt2 = DateFormat.getDateTimeInstance(); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); fmt1 = new BpDateFormat(BpDateFormat.JVM_DATE_ONLY, null); fmt2 = DateFormat.getDateInstance(DateFormat.SHORT); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); fmt1 = new BpDateFormat(BpDateFormat.JVM_TIME_ONLY, null); fmt2 = DateFormat.getTimeInstance(DateFormat.SHORT); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); fmt1 = new BpDateFormat(BpDateFormat.JVM_FULL_DATE, null); fmt2 = DateFormat.getDateInstance(DateFormat.FULL); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); fmt1 = new BpDateFormat(BpDateFormat.JVM_DATE_TIME, Locale.CANADA_FRENCH); fmt2 = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.CANADA_FRENCH); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); }
From source file:com.espian.ticktock.AddEditActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_add: ContentValues cvs = new ContentValues(); String label = mTitle.getText().toString(); if (label == null || label.isEmpty()) { Toast.makeText(this, R.string.no_empty_label, Toast.LENGTH_SHORT).show(); return true; }/* w w w .j av a2s. com*/ cvs.put("label", label); cvs.put("date", DateFormat.getDateInstance(DateFormat.LONG).format(mDatePicker.getSelectedDate())); if (isEdit) { int updateResult = getContentResolver().update(TickTockProvider.countdownUri, cvs, BaseColumns._ID + "=?", new String[] { editId + "" }); if (updateResult == 1) { setResult(RESULT_OK); finish(); } else { Toast.makeText(this, getString(R.string.failed_update, mTitle.getText().toString()), Toast.LENGTH_SHORT).show(); } } else { Uri result = getContentResolver().insert(TickTockProvider.countdownUri, cvs); if (result != null) { setResult(RESULT_OK); finish(); } else { Toast.makeText(this, getString(R.string.failed_add, mTitle.getText().toString()), Toast.LENGTH_SHORT).show(); } } break; case R.id.menu_discard: setResult(RESULT_CANCELED); finish(); break; } return true; }
From source file:com.exp.tracker.services.impl.EmailServicesHelper.java
/** * Sends settlement notice.// w ww. jav a2 s. c o m * * @param sb * The settlement bean. * @param ul * The user bean list. * @param settlementReport * The settlement report pdf bytes. * @param expenseReport * The expense report PDF bytes. */ protected void sendSettlementNotice(SettlementBean sb, List<UserBean> ul, byte[] settlementReport, byte[] expenseReport) { // Attachment Map Map<String, byte[]> emailAttachments = new HashMap<String, byte[]>(); emailAttachments.put("SettlementReport.pdf", settlementReport); emailAttachments.put("ExpenseReport.pdf", expenseReport); for (UserBean ub : ul) { // The email id array. String[] emailIdStrings = { ub.getEmailId() }; // Email subject. String emailSubject = "New Settlement generated."; // Message Content Map<String, Object> model = new HashMap<String, Object>(); model.put("user", ub); DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM); String startDate = df.format(sb.getStartDate()); String endDate = df.format(sb.getEndDate()); model.put("startDate", startDate); model.put("endDate", endDate); sendEmailInternal(emailIdStrings, emailSubject, "com/exp/tracker/email/templates/velocity/settlement-notice.vm", model, emailAttachments); } }
From source file:de.tobiasbielefeld.solitaire.ui.Statistics.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activty_statistics); int padding = (int) getResources().getDimension(R.dimen.statistics_table_padding); int textSize = getResources().getInteger(R.integer.statistics_text_size); boolean addedEntries = false; TableRow row;/* w w w . jav a 2s .c om*/ if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); tableLayout = (TableLayout) findViewById(R.id.statisticsTableHighScores); textWonGames = (TextView) findViewById(R.id.statisticsTextViewGamesWon); textWinPercentage = (TextView) findViewById(R.id.statisticsTextViewWinPercentage); loadData(); for (int i = 0; i < Scores.MAX_SAVED_SCORES; i++) { //for each entry in highScores, add a new view with it if (scores.get(i, 0) == 0) //if the score is zero, don't show it continue; if (!addedEntries) addedEntries = true; row = new TableRow(this); TextView textView1 = new TextView(this); TextView textView2 = new TextView(this); TextView textView3 = new TextView(this); TextView textView4 = new TextView(this); textView1.setText(String.format(Locale.getDefault(), "%s", scores.get(i, 0))); textView2.setText(String.format(Locale.getDefault(), "%02d:%02d:%02d", //add it to the view scores.get(i, 1) / 3600, (scores.get(i, 1) % 3600) / 60, (scores.get(i, 1) % 60))); textView3.setText(DateFormat.getDateInstance(DateFormat.SHORT).format(scores.get(i, 2))); //textView4.setText(DateFormat.getTimeInstance(DateFormat.SHORT).format(scores.get(i,2))); textView4.setText(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(scores.get(i, 2))); textView1.setPadding(padding, 0, padding, 0); textView2.setPadding(padding, 0, padding, 0); textView3.setPadding(padding, 0, padding, 0); textView4.setPadding(padding, 0, padding, 0); textView1.setTextSize(textSize); textView2.setTextSize(textSize); textView3.setTextSize(textSize); textView4.setTextSize(textSize); textView1.setGravity(Gravity.CENTER); textView2.setGravity(Gravity.CENTER); textView3.setGravity(Gravity.CENTER); textView4.setGravity(Gravity.CENTER); row.addView(textView1); row.addView(textView2); row.addView(textView3); row.addView(textView4); row.setGravity(Gravity.CENTER); tableLayout.addView(row); } }