java.text.SimpleDateFormat.getDateTimeInstance()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(176)

本文整理了Java中java.text.SimpleDateFormat.getDateTimeInstance()方法的一些代码示例,展示了SimpleDateFormat.getDateTimeInstance()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SimpleDateFormat.getDateTimeInstance()方法的具体详情如下:
包路径:java.text.SimpleDateFormat
类名称:SimpleDateFormat
方法名:getDateTimeInstance

SimpleDateFormat.getDateTimeInstance介绍

暂无

代码示例

代码示例来源:origin: plutext/docx4j

  1. protected Map<String, SimpleDateFormat> initialValue() {
  2. HashMap<String, SimpleDateFormat> hashMap = new HashMap<String, SimpleDateFormat>();
  3. hashMap.put(null, (SimpleDateFormat)SimpleDateFormat.getDateTimeInstance());
  4. return hashMap;
  5. }
  6. };

代码示例来源:origin: log4j/log4j

  1. private synchronized void configure() {
  2. _dateFormat = SimpleDateFormat.getDateTimeInstance(DateFormat.FULL,
  3. DateFormat.FULL,
  4. getLocale());
  5. _dateFormat.setTimeZone(getTimeZone());
  6. if (_pattern != null) {
  7. ((SimpleDateFormat) _dateFormat).applyPattern(_pattern);
  8. }
  9. }

代码示例来源:origin: plutext/docx4j

  1. /**
  2. * @param language abbreviation like "fr-CA",
  3. * @return SimpleDateFormat instance for specified language
  4. * if null will @return SimpleDateFormat.getDateTimeInstance()
  5. */
  6. private static SimpleDateFormat getSimpleDateFormat(String lang) {
  7. Map<String, SimpleDateFormat> dateFormatsMap = DATE_FORMATS.get();
  8. SimpleDateFormat dateFormat = dateFormatsMap.get(lang);
  9. if (dateFormat == null) {
  10. // dateFormat = (SimpleDateFormat)SimpleDateFormat.getDateTimeInstance(DateFormat.DEFAULT, 0, Locale.forLanguageTag(lang));
  11. // Be Java 6 compatible
  12. dateFormat = (SimpleDateFormat)SimpleDateFormat.getDateTimeInstance(DateFormat.DEFAULT, 0,
  13. localeforLanguageTag(lang));
  14. dateFormatsMap.put(lang, dateFormat);
  15. }
  16. return dateFormat;
  17. }

代码示例来源:origin: confluentinc/ksql

  1. @Test
  2. public void shouldHandleNullValuesFromSTRINGPrint() throws IOException {
  3. final DateFormat dateFormat =
  4. SimpleDateFormat.getDateTimeInstance(3, 1, Locale.getDefault());
  5. final ConsumerRecord<String, Bytes> record = new ConsumerRecord<>(
  6. "some-topic", 1, 1, "key", null);
  7. final String formatted =
  8. Format.STRING.maybeGetFormatter(
  9. "some-topic", record, null, dateFormat).get().print(record);
  10. assertThat(formatted, endsWith(", key , NULL\n"));
  11. }

代码示例来源:origin: eclipse/paho.mqtt.android

  1. /**
  2. * Add an action to the history of the client
  3. * @param action the history item to add
  4. */
  5. public void addAction(String action) {
  6. Object[] args = new String[1];
  7. DateFormat dateTimeFormatter = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
  8. args[0] = dateTimeFormatter.format(new Date());
  9. String timestamp = context.getString(R.string.timestamp, args);
  10. history.add(action + timestamp);
  11. notifyListeners(new PropertyChangeEvent(this, ActivityConstants.historyProperty, null, null));
  12. }

代码示例来源:origin: eclipse/paho.mqtt.android

  1. @NonNull
  2. @Override
  3. public View getView(final int position, View convertView, @NonNull ViewGroup parent){
  4. LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  5. View rowView = inflater.inflate(R.layout.message_list_item, parent, false);
  6. TextView topicTextView = (TextView) rowView.findViewById(R.id.message_topic_text);
  7. TextView messageTextView = (TextView) rowView.findViewById(R.id.message_text);
  8. TextView dateTextView = (TextView) rowView.findViewById(R.id.message_date_text);
  9. messageTextView.setText(new String(messages.get(position).getMessage().getPayload()));
  10. topicTextView.setText(context.getString(R.string.topic_fmt, messages.get(position).getTopic()));
  11. DateFormat dateTimeFormatter = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
  12. String shortDateStamp = dateTimeFormatter.format(messages.get(position).getTimestamp());
  13. dateTextView.setText(context.getString(R.string.message_time_fmt, shortDateStamp));
  14. return rowView;
  15. }
  16. }

代码示例来源:origin: vekexasia/android-edittext-validator

  1. @SuppressLint("SimpleDateFormat")
  2. @Override
  3. public boolean isValid(EditText et) {
  4. if (TextUtils.isEmpty(et.getText()))
  5. return true;
  6. String value = et.getText().toString();
  7. for (String _format : formats) {
  8. DateFormat format;
  9. if ("DefaultDate".equalsIgnoreCase(_format)) {
  10. format = SimpleDateFormat.getDateInstance();
  11. } else if ("DefaultTime".equalsIgnoreCase(_format)) {
  12. format = SimpleDateFormat.getTimeInstance();
  13. } else if ("DefaultDateTime".equalsIgnoreCase(_format)) {
  14. format = SimpleDateFormat.getDateTimeInstance();
  15. } else {
  16. format = new SimpleDateFormat(_format);
  17. }
  18. Date date = null;
  19. try {
  20. date = format.parse(value);
  21. } catch (ParseException e) {
  22. return false;
  23. }
  24. if (date != null) {
  25. return true;
  26. }
  27. }
  28. return false;
  29. }

代码示例来源:origin: owlike/genson

  1. public DateConverter(DateFormat dateFormat, boolean asTimeInMillis) {
  2. if (dateFormat == null) dateFormat = SimpleDateFormat.getDateTimeInstance();
  3. this.dateFormat = dateFormat;
  4. this.asTimeInMillis = asTimeInMillis;
  5. }

代码示例来源:origin: apache/metron

  1. String outputDirName = outputDirFormatter.format(beginNS, endNS, filterImpl.queryToString(fields));
  2. if(LOG.isDebugEnabled()) {
  3. DateFormat format = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.LONG
  4. , SimpleDateFormat.LONG
  5. );

代码示例来源:origin: DSpace/DSpace

  1. @Override
  2. protected DateFormat initialValue() {
  3. DateFormat dateTimeInstance = SimpleDateFormat.getDateTimeInstance();
  4. dateTimeInstance.setTimeZone(UTC_ZONE);
  5. return dateTimeInstance;
  6. }
  7. };

代码示例来源:origin: tinyMediaManager/tinyMediaManager

  1. public String getDateAddedAsString() {
  2. if (dateAdded == null) {
  3. return "";
  4. }
  5. return SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.getDefault()).format(dateAdded);
  6. }

代码示例来源:origin: espertechinc/esper

  1. public void onComplexEvent(String theEvent) {
  2. DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance();
  3. String date = dateFormat.format(new Date());
  4. System.out.println("CEP: " + date + " " + theEvent);
  5. }
  6. }

代码示例来源:origin: toutatice-portail.cms/toutatice-portail-cms-nuxeo-taglib

  1. /**
  2. * Generate comment creation date DOM4J element.
  3. *
  4. * @param locale user locale
  5. * @param date comment creation date
  6. * @return DOM4J element
  7. */
  8. private Element generateDate(Locale locale, Date date) {
  9. DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale);
  10. return DOM4JUtils.generateElement(HTMLConstants.SPAN, null, dateFormat.format(date));
  11. }

代码示例来源:origin: org.apache.openejb/openejb-core

  1. @Managed
  2. public String getLatest() {
  3. final long last = this.last.get();
  4. if (last <= 0) {
  5. return "-";
  6. }
  7. final DateFormat format = SimpleDateFormat.getDateTimeInstance();
  8. return format.format(new Date(last));
  9. }

代码示例来源:origin: iterate-ch/cyberduck

  1. @Override
  2. public String getMediumFormat(final long milliseconds, final boolean natural) {
  3. if(-1 == milliseconds) {
  4. return LocaleFactory.localizedString("Unknown");
  5. }
  6. final DateFormat format = SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
  7. format.setTimeZone(TimeZone.getTimeZone(tz));
  8. return format.format(milliseconds);
  9. }

代码示例来源:origin: iterate-ch/cyberduck

  1. @Override
  2. public String getLongFormat(final long milliseconds, final boolean natural) {
  3. if(-1 == milliseconds) {
  4. return LocaleFactory.localizedString("Unknown");
  5. }
  6. final DateFormat format = SimpleDateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
  7. format.setTimeZone(TimeZone.getTimeZone(tz));
  8. return format.format(milliseconds);
  9. }
  10. }

代码示例来源:origin: iterate-ch/cyberduck

  1. @Override
  2. public String getShortFormat(final long milliseconds, final boolean natural) {
  3. if(-1 == milliseconds) {
  4. return LocaleFactory.localizedString("Unknown");
  5. }
  6. final DateFormat format = SimpleDateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
  7. format.setTimeZone(TimeZone.getTimeZone(tz));
  8. return format.format(milliseconds);
  9. }

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

  1. private synchronized void configure() {
  2. _dateFormat = SimpleDateFormat.getDateTimeInstance(DateFormat.FULL,
  3. DateFormat.FULL,
  4. getLocale());
  5. _dateFormat.setTimeZone(getTimeZone());
  6. if (_pattern != null) {
  7. ((SimpleDateFormat) _dateFormat).applyPattern(_pattern);
  8. }
  9. }

代码示例来源:origin: info.magnolia/magnolia-core

  1. /**
  2. * Uses the current locale (user) to parse the date and time.
  3. *
  4. * @param dateStr Date or Calendar
  5. * @return the String
  6. */
  7. public static Date parseDateTime(String dateStr) throws ParseException {
  8. DateFormat format = SimpleDateFormat.getDateTimeInstance(
  9. FastDateFormat.SHORT,
  10. FastDateFormat.SHORT,
  11. MgnlContext.getLocale());
  12. return (Date) format.parseObject(dateStr);
  13. }

代码示例来源:origin: boonproject/boon

  1. public static String getGMTString(Date date) {
  2. /*
  3. * To SL: Now I know what you mean work everywhere. :)
  4. * We format our dates differently here.
  5. * DAY/MONTH/YEAR although logical and done everywhere. :)
  6. * --RMH
  7. */
  8. DateFormat df = SimpleDateFormat.getDateTimeInstance( DateFormat.SHORT,
  9. DateFormat.SHORT, Locale.FRANCE );
  10. df.setTimeZone(TimeZone.getTimeZone("GMT"));
  11. return df.format(date);
  12. }
  13. }

相关文章

SimpleDateFormat类方法