ItemAdapter(Context context) { mInflater = LayoutInflater.from(context); dateFormat = SimpleDateFormat.getDateInstance(DateFormat.DEFAULT, Locale.ENGLISH); }
private boolean isMonthFirst(){ SimpleDateFormat format = (SimpleDateFormat)SimpleDateFormat.getDateInstance(SimpleDateFormat.FULL); String pattern = format.toLocalizedPattern(); return pattern.indexOf("M") < pattern.indexOf("d"); }
@Override public void onPositiveActionClicked(DialogFragment fragment) { DatePickerDialog dialog = (DatePickerDialog)fragment.getDialog(); String date = dialog.getFormattedDate(SimpleDateFormat.getDateInstance()); Toast.makeText(mActivity, "Date is " + date, Toast.LENGTH_SHORT).show(); super.onPositiveActionClicked(fragment); }
private static String formatDate(FldSimpleModel model, String format, Date date, String lang) { DateFormat dateFormat = null; if ((format != null) && (format.length() > 0)) { SimpleDateFormat simpleDateFormat = getSimpleDateFormat(lang); simpleDateFormat.applyPattern(convertDatePattern(format)); dateFormat = simpleDateFormat; } else { dateFormat = (model.getFldName().indexOf("DATE") > -1 ? SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT) : SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT)); } return dateFormat.format(date); }
@SuppressLint("SimpleDateFormat") @Override public boolean isValid(EditText et) { if (TextUtils.isEmpty(et.getText())) return true; String value = et.getText().toString(); for (String _format : formats) { DateFormat format; if ("DefaultDate".equalsIgnoreCase(_format)) { format = SimpleDateFormat.getDateInstance(); } else if ("DefaultTime".equalsIgnoreCase(_format)) { format = SimpleDateFormat.getTimeInstance(); } else if ("DefaultDateTime".equalsIgnoreCase(_format)) { format = SimpleDateFormat.getDateTimeInstance(); } else { format = new SimpleDateFormat(_format); } Date date = null; try { date = format.parse(value); } catch (ParseException e) { return false; } if (date != null) { return true; } } return false; }
public AgeValidator() { message = DEFAULT_MESSAGE; age = DEFAULT_AGE; sdf = SimpleDateFormat.getDateInstance(); }
/** * Get the dd/mm/yyyy date formatting pattern for a given locale * This is a bit of a hack.. * * @param dateLocale * @return the pattern using DateFormatSymbols */ public static String getPatternForDateLocale(Locale dateLocale) { SimpleDateFormat dateFormat = (SimpleDateFormat) (SimpleDateFormat.getDateInstance(DateFormat.SHORT, dateLocale)); return dateFormat.toPattern(); }
/** * Gets the first aired as a string, formatted in the system locale. * * @return the first aired as string */ public String getFirstAiredAsString() { if (this.firstAired == null) { return ""; } return SimpleDateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(firstAired); }
/** * Gets the first aired as a string, formatted in the system locale. * * @return the first aired as string */ public String getFirstAiredAsString() { if (this.firstAired == null) { return ""; } return SimpleDateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(firstAired); }
/** * Gets the first aired as a string, formatted in the system locale. */ public String getReleaseDateAsString() { if (this.releaseDate == null) { return ""; } return SimpleDateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(releaseDate); }
private void changeShowDate() { String dateStr = SimpleDateFormat.getDateInstance().format(startDate.getTime()); // Dec 19, 2018 startDateBtn.setText(dateStr); }
private ComponentFormatDefaults() { formats = new HashMap<Key, DateFormat>(); formats.put(Key.TODAY_SELECTOR, SimpleDateFormat.getDateInstance(SimpleDateFormat.MEDIUM)); formats.put(Key.DOW_HEADER, new SimpleDateFormat("EE")); formats.put(Key.MONTH_SELECTOR, new SimpleDateFormat("MMMM")); formats.put(Key.SELECTED_DATE_FIELD, SimpleDateFormat.getDateInstance(SimpleDateFormat.MEDIUM)); }
/** * Uses the current locale (user) to parse the date. * * @param dateStr Date or Calendar * @return the String */ public static Date parseDate(String dateStr) throws ParseException { DateFormat format = SimpleDateFormat.getDateInstance( FastDateFormat.SHORT, MgnlContext.getLocale()); return format.parse(dateStr); }
private String getDefaultDatePattern(Object componentLocale) { Locale locale = getObjectAsLocale(componentLocale); // Note: The following usage of SimpleDateFormat is thread-safe, since only the result of the toPattern() // method is utilized. SimpleDateFormat simpleDateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.MEDIUM, locale); return simpleDateFormat.toPattern(); }
private String getDefaultDatePattern(Object componentLocale) { Locale locale = getObjectAsLocale(componentLocale); // Note: The following usage of SimpleDateFormat is thread-safe, since only the result of the toPattern() // method is utilized. SimpleDateFormat simpleDateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.MEDIUM, locale); return simpleDateFormat.toPattern(); } }
/** * Gets date. * * @return the date */ public String getDate() { DateFormat format = SimpleDateFormat.getDateInstance(); return getDate(format); }
/** * Format the string according to the parameter isDate * @param isDate: date formating or time formating * @return */ public String toString(boolean isDate) { GregorianCalendar calendar = new GregorianCalendar(year, monthOfYear, dayOfMonth, startTimeOfDay, startMinute); calendar.setTimeZone(TimeZone.getTimeZone("GMT0")); DateFormat instance = isDate ? SimpleDateFormat.getDateInstance() : SimpleDateFormat.getTimeInstance(DateFormat.SHORT); instance.setTimeZone(TimeZone.getTimeZone("GMT0")); return instance.format(calendar.getTime()); }
private PatternFormat createLocalPattern(String name, int dateStyle, Integer timeStyle) { final SimpleDateFormat simpleDateFormat = (SimpleDateFormat) (timeStyle == null ? SimpleDateFormat .getDateInstance(dateStyle, locale) : SimpleDateFormat.getDateTimeInstance(dateStyle, timeStyle, locale)); final String dStyle = PatternFormat.STYLE_DATE; final String dType = IFormattedObject.TYPE_DATE; return createFormat(simpleDateFormat.toPattern(), dStyle, dType, name, locale); }
private DateFormat getWeeklyCaptionFormatter() { if (weeklyCaptionFormat != null) { return new SimpleDateFormat(weeklyCaptionFormat, getLocale()); } else { return SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, getLocale()); } }
@Before public void setUp() throws ParseException { // Output logs emitted during tests so they may be accessed ShadowLog.stream = System.out; final DateFormat dateFormatter = SimpleDateFormat.getDateInstance(); nowString = dateFormatter.format(System.currentTimeMillis()); nowMs = dateFormatter.parse(nowString).getTime(); }