protected Map<String, SimpleDateFormat> initialValue() { HashMap<String, SimpleDateFormat> hashMap = new HashMap<String, SimpleDateFormat>(); hashMap.put(null, (SimpleDateFormat)SimpleDateFormat.getDateTimeInstance()); return hashMap; } };
private synchronized void configure() { _dateFormat = SimpleDateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, getLocale()); _dateFormat.setTimeZone(getTimeZone()); if (_pattern != null) { ((SimpleDateFormat) _dateFormat).applyPattern(_pattern); } }
/** * @param language abbreviation like "fr-CA", * @return SimpleDateFormat instance for specified language * if null will @return SimpleDateFormat.getDateTimeInstance() */ private static SimpleDateFormat getSimpleDateFormat(String lang) { Map<String, SimpleDateFormat> dateFormatsMap = DATE_FORMATS.get(); SimpleDateFormat dateFormat = dateFormatsMap.get(lang); if (dateFormat == null) { // dateFormat = (SimpleDateFormat)SimpleDateFormat.getDateTimeInstance(DateFormat.DEFAULT, 0, Locale.forLanguageTag(lang)); // Be Java 6 compatible dateFormat = (SimpleDateFormat)SimpleDateFormat.getDateTimeInstance(DateFormat.DEFAULT, 0, localeforLanguageTag(lang)); dateFormatsMap.put(lang, dateFormat); } return dateFormat; }
@Test public void shouldHandleNullValuesFromSTRINGPrint() throws IOException { final DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance(3, 1, Locale.getDefault()); final ConsumerRecord<String, Bytes> record = new ConsumerRecord<>( "some-topic", 1, 1, "key", null); final String formatted = Format.STRING.maybeGetFormatter( "some-topic", record, null, dateFormat).get().print(record); assertThat(formatted, endsWith(", key , NULL\n")); }
/** * Add an action to the history of the client * @param action the history item to add */ public void addAction(String action) { Object[] args = new String[1]; DateFormat dateTimeFormatter = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); args[0] = dateTimeFormatter.format(new Date()); String timestamp = context.getString(R.string.timestamp, args); history.add(action + timestamp); notifyListeners(new PropertyChangeEvent(this, ActivityConstants.historyProperty, null, null)); }
@NonNull @Override public View getView(final int position, View convertView, @NonNull ViewGroup parent){ LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.message_list_item, parent, false); TextView topicTextView = (TextView) rowView.findViewById(R.id.message_topic_text); TextView messageTextView = (TextView) rowView.findViewById(R.id.message_text); TextView dateTextView = (TextView) rowView.findViewById(R.id.message_date_text); messageTextView.setText(new String(messages.get(position).getMessage().getPayload())); topicTextView.setText(context.getString(R.string.topic_fmt, messages.get(position).getTopic())); DateFormat dateTimeFormatter = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); String shortDateStamp = dateTimeFormatter.format(messages.get(position).getTimestamp()); dateTextView.setText(context.getString(R.string.message_time_fmt, shortDateStamp)); return rowView; } }
@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 DateConverter(DateFormat dateFormat, boolean asTimeInMillis) { if (dateFormat == null) dateFormat = SimpleDateFormat.getDateTimeInstance(); this.dateFormat = dateFormat; this.asTimeInMillis = asTimeInMillis; }
String outputDirName = outputDirFormatter.format(beginNS, endNS, filterImpl.queryToString(fields)); if(LOG.isDebugEnabled()) { DateFormat format = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.LONG , SimpleDateFormat.LONG );
@Override protected DateFormat initialValue() { DateFormat dateTimeInstance = SimpleDateFormat.getDateTimeInstance(); dateTimeInstance.setTimeZone(UTC_ZONE); return dateTimeInstance; } };
public String getDateAddedAsString() { if (dateAdded == null) { return ""; } return SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.getDefault()).format(dateAdded); }
public void onComplexEvent(String theEvent) { DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance(); String date = dateFormat.format(new Date()); System.out.println("CEP: " + date + " " + theEvent); } }
/** * Generate comment creation date DOM4J element. * * @param locale user locale * @param date comment creation date * @return DOM4J element */ private Element generateDate(Locale locale, Date date) { DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale); return DOM4JUtils.generateElement(HTMLConstants.SPAN, null, dateFormat.format(date)); }
@Managed public String getLatest() { final long last = this.last.get(); if (last <= 0) { return "-"; } final DateFormat format = SimpleDateFormat.getDateTimeInstance(); return format.format(new Date(last)); }
@Override public String getMediumFormat(final long milliseconds, final boolean natural) { if(-1 == milliseconds) { return LocaleFactory.localizedString("Unknown"); } final DateFormat format = SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); format.setTimeZone(TimeZone.getTimeZone(tz)); return format.format(milliseconds); }
@Override public String getLongFormat(final long milliseconds, final boolean natural) { if(-1 == milliseconds) { return LocaleFactory.localizedString("Unknown"); } final DateFormat format = SimpleDateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL); format.setTimeZone(TimeZone.getTimeZone(tz)); return format.format(milliseconds); } }
@Override public String getShortFormat(final long milliseconds, final boolean natural) { if(-1 == milliseconds) { return LocaleFactory.localizedString("Unknown"); } final DateFormat format = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); format.setTimeZone(TimeZone.getTimeZone(tz)); return format.format(milliseconds); }
private synchronized void configure() { _dateFormat = SimpleDateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, getLocale()); _dateFormat.setTimeZone(getTimeZone()); if (_pattern != null) { ((SimpleDateFormat) _dateFormat).applyPattern(_pattern); } }
/** * Uses the current locale (user) to parse the date and time. * * @param dateStr Date or Calendar * @return the String */ public static Date parseDateTime(String dateStr) throws ParseException { DateFormat format = SimpleDateFormat.getDateTimeInstance( FastDateFormat.SHORT, FastDateFormat.SHORT, MgnlContext.getLocale()); return (Date) format.parseObject(dateStr); }
public static String getGMTString(Date date) { /* * To SL: Now I know what you mean work everywhere. :) * We format our dates differently here. * DAY/MONTH/YEAR although logical and done everywhere. :) * --RMH */ DateFormat df = SimpleDateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT, Locale.FRANCE ); df.setTimeZone(TimeZone.getTimeZone("GMT")); return df.format(date); } }