List of usage examples for java.text DateFormat getDateInstance
public static final DateFormat getDateInstance()
From source file:org.dharmaseed.android.TalkCursorAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { // Set talk title and teacher name TextView title = (TextView) view.findViewById(R.id.item_view_title); TextView teacher = (TextView) view.findViewById(R.id.item_view_detail1); TextView center = (TextView) view.findViewById(R.id.item_view_detail2); title.setText(getString(cursor, DBManager.C.Talk.TABLE_NAME + "." + DBManager.C.Talk.TITLE)); teacher.setText(getString(cursor, DBManager.C.Teacher.TABLE_NAME + "." + DBManager.C.Teacher.NAME)); center.setText(getString(cursor, DBManager.C.Center.TABLE_NAME + "." + DBManager.C.Teacher.NAME)); // Set date/*from w w w . j a v a 2 s. c om*/ TextView date = (TextView) view.findViewById(R.id.item_view_detail3); String recDate = getString(cursor, DBManager.C.Talk.TABLE_NAME + "." + DBManager.C.Talk.RECORDING_DATE); try { date.setText(DateFormat.getDateInstance().format(parser.parse(recDate))); } catch (ParseException e) { date.setText(""); } // Set the talk duration final TextView durationView = (TextView) view.findViewById(R.id.item_view_detail4); double duration = cursor.getDouble(cursor.getColumnIndexOrThrow( DBManager.getAlias(DBManager.C.Talk.TABLE_NAME + "." + DBManager.C.Talk.DURATION_IN_MINUTES))); String durationStr = DateUtils.formatElapsedTime((long) (duration * 60)); durationView.setText(durationStr); // Set teacher photo String photoFilename = DBManager.getTeacherPhotoFilename(cursor.getInt(cursor.getColumnIndexOrThrow( DBManager.getAlias(DBManager.C.Talk.TABLE_NAME + "." + DBManager.C.Talk.TEACHER_ID)))); ImageView photoView = (ImageView) view.findViewById(R.id.item_view_photo); try { FileInputStream photo = context.openFileInput(photoFilename); photoView.setImageBitmap(BitmapFactory.decodeStream(photo)); } catch (FileNotFoundException e) { Drawable icon = ContextCompat.getDrawable(context, R.drawable.dharmaseed_icon); photoView.setImageDrawable(icon); } // Set talk stars handleStars(view, cursor.getInt(cursor.getColumnIndexOrThrow(DBManager.C.Talk.ID))); }
From source file:de.tobiasbielefeld.solitaire.ui.about.InformationFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_about_tab1, container, false); TextView textViewBuildDate = (TextView) view.findViewById(R.id.aboutTextViewBuild); //build date TextView textViewAppVersion = (TextView) view.findViewById(R.id.aboutTextViewVersion); //app version TextView textViewGitHubLink = (TextView) view.findViewById(R.id.aboutTextViewGitHubLink); //link for the gitHub repo TextView textViewLicenseLink = (TextView) view.findViewById(R.id.aboutTextViewLicenseLink); TextView textJapaneseContributors = (TextView) view.findViewById(R.id.about_japanese_contributors); TextView textEsperantoContributors = (TextView) view.findViewById(R.id.about_esperanto_contributors); TextView textPolishContributors = (TextView) view.findViewById(R.id.about_polish_contributors); TextView textFrenchContributors = (TextView) view.findViewById(R.id.about_french_contributors); TextView textFinnishContributors = (TextView) view.findViewById(R.id.about_finnish_contributors); TextView textTurkishContributors = (TextView) view.findViewById(R.id.about_turkish_contributors); TextView textSpanishArgentinaContributors = (TextView) view .findViewById(R.id.about_spanish_argentina_contributers); TextView textFurtherContributors1 = (TextView) view.findViewById(R.id.about_further_contributors_1); TextView textFurtherContributors2 = (TextView) view.findViewById(R.id.about_further_contributors_2); TextView textFurtherContributors3 = (TextView) view.findViewById(R.id.about_further_contributors_3); String buildDate = DateFormat.getDateInstance().format(BuildConfig.TIMESTAMP); //get the build date in locale time format //update the textViews textViewAppVersion.setText(stringFormat(BuildConfig.VERSION_NAME)); textViewBuildDate.setText(stringFormat(buildDate)); //enable the hyperlink clicks TextView[] textViews = new TextView[] { textViewGitHubLink, textViewLicenseLink, textJapaneseContributors, textEsperantoContributors, textPolishContributors, textFinnishContributors, textTurkishContributors, textFrenchContributors, textFurtherContributors1, textFurtherContributors2, textFurtherContributors3, textSpanishArgentinaContributors }; for (TextView textView : textViews) { textView.setMovementMethod(LinkMovementMethod.getInstance()); }/* w w w.j a va 2s . c o m*/ return view; }
From source file:bbct.android.common.activity.MainActivity.java
private void showSurvey1Dialog() { DateFormat dateFormat = DateFormat.getDateInstance(); Date today = new Date(); final String todayStr = dateFormat.format(today); if (!prefs.contains(SharedPreferenceKeys.INSTALL_DATE)) { prefs.edit().putString(SharedPreferenceKeys.INSTALL_DATE, todayStr).apply(); }/*from w w w . j av a2s.c om*/ if (!prefs.contains(SharedPreferenceKeys.SURVEY1_DATE)) { String installDate = prefs.getString(SharedPreferenceKeys.INSTALL_DATE, today.toString()); try { Calendar cal = Calendar.getInstance(); cal.setTime(dateFormat.parse(installDate)); cal.add(Calendar.DATE, SURVEY_DELAY); if (today.after(cal.getTime())) { DialogUtil.showSurveyDialog(this, todayStr, R.string.survey1, SharedPreferenceKeys.SURVEY1_DATE, SURVEY1_URI); } } catch (ParseException e) { Log.d(TAG, "Error parsing install date"); e.printStackTrace(); } } }
From source file:Main.java
public Main() { setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JPanel buttonPanel = new JPanel(); okButton = new JButton("Ok"); buttonPanel.add(okButton);/* w w w . ja va 2 s .c o m*/ add(buttonPanel, BorderLayout.SOUTH); mainPanel = new JPanel(); mainPanel.setLayout(new GridLayout(0, 3)); add(mainPanel, BorderLayout.CENTER); JSpinner defaultSpinner = new JSpinner(); addRow("Default", defaultSpinner); JSpinner boundedSpinner = new JSpinner(new SpinnerNumberModel(5, 0, 10, 0.5)); addRow("Bounded", boundedSpinner); String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); JSpinner listSpinner = new JSpinner(new SpinnerListModel(fonts)); addRow("List", listSpinner); JSpinner reverseListSpinner = new JSpinner(new SpinnerListModel(fonts) { public Object getNextValue() { return super.getPreviousValue(); } public Object getPreviousValue() { return super.getNextValue(); } }); addRow("Reverse List", reverseListSpinner); JSpinner dateSpinner = new JSpinner(new SpinnerDateModel()); addRow("Date", dateSpinner); JSpinner betterDateSpinner = new JSpinner(new SpinnerDateModel()); String pattern = ((SimpleDateFormat) DateFormat.getDateInstance()).toPattern(); betterDateSpinner.setEditor(new JSpinner.DateEditor(betterDateSpinner, pattern)); addRow("Better Date", betterDateSpinner); JSpinner timeSpinner = new JSpinner(new SpinnerDateModel()); pattern = ((SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT)).toPattern(); timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, pattern)); addRow("Time", timeSpinner); JSpinner permSpinner = new JSpinner(new PermutationSpinnerModel("meat")); addRow("Word permutations", permSpinner); }
From source file:com.mobileman.projecth.business.patient.PatientQuestionAnswerServiceTest.java
/** * @throws Exception//ww w .ja va 2s .c o m */ @Test public void saveAnswer() throws Exception { Question question = questionService.findAll().get(0); Answer answer = question.getQuestionType().getAnswers().get(0); User patient = userService.findUserByLogin("sysuser1"); assertNotNull(patient); DateFormat dateFormat = DateFormat.getDateInstance(); Date logDate = dateFormat.parse("1.1.2011"); int count = patientQuestionAnswerService.findAll().size(); patientQuestionAnswerService.saveAnswer(patient.getId(), question.getId(), answer.getId(), "custom", logDate); assertEquals(count + 1, patientQuestionAnswerService.findAll().size()); }
From source file:com.haulmont.chile.core.datatypes.impl.DateDatatype.java
@Override public Date parse(String value) throws ParseException { if (StringUtils.isBlank(value)) { return null; }//from w w w . j a v a 2s. c o m DateFormat format; if (formatPattern != null) { format = new SimpleDateFormat(formatPattern); format.setLenient(false); } else { format = DateFormat.getDateInstance(); } return normalize(format.parse(value.trim())); }
From source file:com.pureinfo.srm.product.action.ProductListAction.java
private Date getEndYear() { Date endDate = new Date(); try {// ww w . j ava 2s. c o m if (request.getParameter("endDateYear") == null) { if (m_nEndYear <= 0 || m_nEndYear > RANGE_MAX2) { m_nEndYear = RANGE_END_YEAR; } } else { m_nEndYear = Integer.parseInt(request.getParameter("endDateYear")); } endDate = DateFormat.getDateInstance().parse(m_nEndYear + "-12-31"); } catch (Exception e) { logger.debug("date format error"); } return endDate; }
From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.CswUnmarshallHelper.java
public static Date convertToDate(String value) { // Dates are strings and expected to be in ISO8601 format, YYYY-MM-DD'T'hh:mm:ss.sss, // per annotations in the CSW Record schema. At least the date portion must be present; // the time zone and time are optional. try {//w ww. j av a2 s . c o m return ISODateTimeFormat.dateOptionalTimeParser().parseDateTime(value).toDate(); } catch (IllegalArgumentException e) { LOGGER.debug("Failed to convert to date {} from ISO Format: {}", value, e); } // failed to convert iso format, attempt to convert from xsd:date or xsd:datetime format // this format is used by the NSG interoperability CITE tests try { return CswMarshallHelper.XSD_FACTORY.newXMLGregorianCalendar(value).toGregorianCalendar().getTime(); } catch (IllegalArgumentException e) { LOGGER.debug("Unable to convert date {} from XSD format {} ", value, e); } // try from java date serialization for the default locale try { return DateFormat.getDateInstance().parse(value); } catch (ParseException e) { LOGGER.debug("Unable to convert date {} from default locale format {} ", value, e); } // default to current date LOGGER.warn("Unable to convert {} to a date object, defaulting to current time", value); return new Date(); }
From source file:SpinnerTest.java
public SpinnerFrame() { setTitle("SpinnerTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JPanel buttonPanel = new JPanel(); okButton = new JButton("Ok"); buttonPanel.add(okButton);/*from w w w . j a v a 2s .c om*/ add(buttonPanel, BorderLayout.SOUTH); mainPanel = new JPanel(); mainPanel.setLayout(new GridLayout(0, 3)); add(mainPanel, BorderLayout.CENTER); JSpinner defaultSpinner = new JSpinner(); addRow("Default", defaultSpinner); JSpinner boundedSpinner = new JSpinner(new SpinnerNumberModel(5, 0, 10, 0.5)); addRow("Bounded", boundedSpinner); String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); JSpinner listSpinner = new JSpinner(new SpinnerListModel(fonts)); addRow("List", listSpinner); JSpinner reverseListSpinner = new JSpinner(new SpinnerListModel(fonts) { public Object getNextValue() { return super.getPreviousValue(); } public Object getPreviousValue() { return super.getNextValue(); } }); addRow("Reverse List", reverseListSpinner); JSpinner dateSpinner = new JSpinner(new SpinnerDateModel()); addRow("Date", dateSpinner); JSpinner betterDateSpinner = new JSpinner(new SpinnerDateModel()); String pattern = ((SimpleDateFormat) DateFormat.getDateInstance()).toPattern(); betterDateSpinner.setEditor(new JSpinner.DateEditor(betterDateSpinner, pattern)); addRow("Better Date", betterDateSpinner); JSpinner timeSpinner = new JSpinner(new SpinnerDateModel()); pattern = ((SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT)).toPattern(); timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, pattern)); addRow("Time", timeSpinner); JSpinner permSpinner = new JSpinner(new PermutationSpinnerModel("meat")); addRow("Word permutations", permSpinner); }
From source file:com.qcadoo.plugins.qcadooExport.internal.ExportToCsvController.java
@Monitorable(threshold = 500) @ResponseBody/*w w w . j a v a 2 s . c o m*/ @RequestMapping(value = { CONTROLLER_PATH }, method = RequestMethod.POST) public Object generateCsv(@PathVariable(PLUGIN_IDENTIFIER_VARIABLE) final String pluginIdentifier, @PathVariable(VIEW_NAME_VARIABLE) final String viewName, @RequestBody final JSONObject body, final Locale locale) { try { changeMaxResults(body); ViewDefinitionState state = crudService.invokeEvent(pluginIdentifier, viewName, body, locale); GridComponent grid = (GridComponent) state.getComponentByReference("grid"); String date = DateFormat.getDateInstance().format(new Date()); File file = fileService.createExportFile("export_" + grid.getName() + "_" + date + ".csv"); BufferedWriter output = null; try { output = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))); boolean firstName = true; for (String name : grid.getColumnNames().values()) { if (firstName) { firstName = false; } else { output.append(EXPORTED_DOCUMENT_SEPARATOR); } output.append("\"").append(normalizeString(name)).append("\""); } output.append("\n"); List<Map<String, String>> rows; if (grid.getSelectedEntitiesIds().isEmpty()) { rows = grid.getColumnValuesOfAllRecords(); } else { rows = grid.getColumnValuesOfSelectedRecords(); } for (Map<String, String> row : rows) { boolean firstValue = true; for (String value : row.values()) { if (firstValue) { firstValue = false; } else { output.append(EXPORTED_DOCUMENT_SEPARATOR); } output.append("\"").append(normalizeString(value)).append("\""); } output.append("\n"); } output.flush(); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } finally { IOUtils.closeQuietly(output); } state.redirectTo(fileService.getUrl(file.getAbsolutePath()) + "?clean", true, false); return crudService.renderView(state); } catch (JSONException e) { throw new IllegalStateException(e.getMessage(), e); } }