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

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

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

SimpleDateFormat.toPattern介绍

[英]Returns the pattern of this simple date format using non-localized pattern characters.
[中]使用非本地化模式字符返回此简单日期格式的模式。

代码示例

代码示例来源:origin: prestodb/presto

String getPattern(Locale locale) {
    DateFormat f = null;
    switch (iType) {
      case DATE:
        f = DateFormat.getDateInstance(iDateStyle, locale);
        break;
      case TIME:
        f = DateFormat.getTimeInstance(iTimeStyle, locale);
        break;
      case DATETIME:
        f = DateFormat.getDateTimeInstance(iDateStyle, iTimeStyle, locale);
        break;
    }
    if (f instanceof SimpleDateFormat == false) {
      throw new IllegalArgumentException("No datetime pattern for locale: " + locale);
    }
    return ((SimpleDateFormat) f).toPattern();
  }
}

代码示例来源:origin: stackoverflow.com

Locale locale = Locale.getDefault();
SimpleDateFormat sdf = (SimpleDateFormat)DateFormat.getDateInstance(DateFormat.SHORT, locale );
String format = sdf.toPattern();

代码示例来源:origin: joda-time/joda-time

String getPattern(Locale locale) {
    DateFormat f = null;
    switch (iType) {
      case DATE:
        f = DateFormat.getDateInstance(iDateStyle, locale);
        break;
      case TIME:
        f = DateFormat.getTimeInstance(iTimeStyle, locale);
        break;
      case DATETIME:
        f = DateFormat.getDateTimeInstance(iDateStyle, iTimeStyle, locale);
        break;
    }
    if (f instanceof SimpleDateFormat == false) {
      throw new IllegalArgumentException("No datetime pattern for locale: " + locale);
    }
    return ((SimpleDateFormat) f).toPattern();
  }
}

代码示例来源:origin: org.apache.poi/poi

public static String getJavaDatePattern(int style, Locale locale) {
  DateFormat df = DateFormat.getDateInstance(style, locale);
  if( df instanceof SimpleDateFormat ) {
    return ((SimpleDateFormat)df).toPattern();
  } else {
    switch( style ) {
    case DateFormat.SHORT:
      return "d/MM/yy";
    case DateFormat.MEDIUM:
      return "MMM d, yyyy";
    case DateFormat.LONG:
      return "MMMM d, yyyy";
    case DateFormat.FULL:
      return "dddd, MMMM d, yyyy";
    default:
      return "MMM d, yyyy";
    }
  }
}

代码示例来源:origin: JodaOrg/joda-time

String getPattern(Locale locale) {
    DateFormat f = null;
    switch (iType) {
      case DATE:
        f = DateFormat.getDateInstance(iDateStyle, locale);
        break;
      case TIME:
        f = DateFormat.getTimeInstance(iTimeStyle, locale);
        break;
      case DATETIME:
        f = DateFormat.getDateTimeInstance(iDateStyle, iTimeStyle, locale);
        break;
    }
    if (f instanceof SimpleDateFormat == false) {
      throw new IllegalArgumentException("No datetime pattern for locale: " + locale);
    }
    return ((SimpleDateFormat) f).toPattern();
  }
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) throws Exception {
  for (Locale locale : Locale.getAvailableLocales()) {
    DateFormat df = getShortDateInstanceWithoutYears(locale);
    System.out.println(locale + ": " + df.format(new Date()));      
  }
}

public static DateFormat getShortDateInstanceWithoutYears(Locale locale) {
  SimpleDateFormat sdf = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale);
  sdf.applyPattern(sdf.toPattern().replaceAll("[^\\p{Alpha}]*y+[^\\p{Alpha}]*", ""));
  return sdf;
}

代码示例来源:origin: stackoverflow.com

DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
String pattern       = ((SimpleDateFormat)formatter).toPattern();
String localPattern  = ((SimpleDateFormat)formatter).toLocalizedPattern();

代码示例来源:origin: org.apache.commons/commons-lang3

formatter = DateFormat.getTimeInstance(timeStyle.intValue(), locale);
} else if (timeStyle == null) {
  formatter = DateFormat.getDateInstance(dateStyle.intValue(), locale);
} else {
  formatter = DateFormat.getDateTimeInstance(dateStyle.intValue(), timeStyle.intValue(), locale);
pattern = ((SimpleDateFormat)formatter).toPattern();
final String previous = cDateTimeInstanceCache.putIfAbsent(key, pattern);
if (previous != null) {

代码示例来源:origin: ltsopensource/light-task-scheduler

static String getPatternForStyle(final Integer dateStyle, final Integer timeStyle, final Locale locale) {
  final MultipartKey key = new MultipartKey(dateStyle, timeStyle, locale);
  String pattern = cDateTimeInstanceCache.get(key);
  if (pattern == null) {
    try {
      DateFormat formatter;
      if (dateStyle == null) {
        formatter = DateFormat.getTimeInstance(timeStyle, locale);
      } else if (timeStyle == null) {
        formatter = DateFormat.getDateInstance(dateStyle, locale);
      } else {
        formatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
      }
      pattern = ((SimpleDateFormat) formatter).toPattern();
      final String previous = cDateTimeInstanceCache.putIfAbsent(key, pattern);
      if (previous != null) {
        // even though it doesn't matter if another thread put the pattern
        // it's still good practice to return the String instance that is
        // actually in the ConcurrentMap
        pattern = previous;
      }
    } catch (final ClassCastException ex) {
      throw new IllegalArgumentException("No date time pattern for locale: " + locale);
    }
  }
  return pattern;
}

代码示例来源:origin: ltsopensource/light-task-scheduler

static String getPatternForStyle(final Integer dateStyle, final Integer timeStyle, final Locale locale) {
  final MultipartKey key = new MultipartKey(dateStyle, timeStyle, locale);
  String pattern = cDateTimeInstanceCache.get(key);
  if (pattern == null) {
    try {
      DateFormat formatter;
      if (dateStyle == null) {
        formatter = DateFormat.getTimeInstance(timeStyle, locale);
      } else if (timeStyle == null) {
        formatter = DateFormat.getDateInstance(dateStyle, locale);
      } else {
        formatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
      }
      pattern = ((SimpleDateFormat) formatter).toPattern();
      final String previous = cDateTimeInstanceCache.putIfAbsent(key, pattern);
      if (previous != null) {
        // even though it doesn't matter if another thread put the pattern
        // it's still good practice to return the String instance that is
        // actually in the ConcurrentMap
        pattern = previous;
      }
    } catch (final ClassCastException ex) {
      throw new IllegalArgumentException("No date time pattern for locale: " + locale);
    }
  }
  return pattern;
}

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

private String decodeSimpleDateFormat(StringBuffer buffer, Format format) {
  if (format.equals(DateFormat.getTimeInstance(DateFormat.DEFAULT, locale))) {
    buffer.append(",time");
  } else if (format.equals(DateFormat.getDateInstance(DateFormat.DEFAULT,
      locale))) {
    buffer.append(",date");
  } else if (format.equals(DateFormat.getTimeInstance(DateFormat.SHORT,
      locale))) {
    buffer.append(",time,short");
  } else if (format.equals(DateFormat.getDateInstance(DateFormat.SHORT,
      locale))) {
    buffer.append(",date,short");
  } else if (format.equals(DateFormat.getTimeInstance(DateFormat.LONG,
      locale))) {
    buffer.append(",time,long");
  } else if (format.equals(DateFormat.getDateInstance(DateFormat.LONG,
      locale))) {
    buffer.append(",date,long");
  } else if (format.equals(DateFormat.getTimeInstance(DateFormat.FULL,
      locale))) {
    buffer.append(",time,full");
  } else if (format.equals(DateFormat.getDateInstance(DateFormat.FULL,
      locale))) {
    buffer.append(",date,full");
  } else {
    buffer.append(",date,");
    return ((SimpleDateFormat) format).toPattern();
  }
  return null;
}

代码示例来源:origin: commons-lang/commons-lang

if (format == null) {
  try {
    SimpleDateFormat formatter = (SimpleDateFormat) DateFormat.getDateInstance(style, locale);
    String pattern = formatter.toPattern();
    format = getInstance(pattern, timeZone, locale);
    cDateInstanceCache.put(key, format);

代码示例来源:origin: looly/hutool

formatter = DateFormat.getTimeInstance(timeStyle.intValue(), locale);
} else if (timeStyle == null) {
  formatter = DateFormat.getDateInstance(dateStyle.intValue(), locale);
} else {
  formatter = DateFormat.getDateTimeInstance(dateStyle.intValue(), timeStyle.intValue(), locale);
pattern = ((SimpleDateFormat) formatter).toPattern();
final String previous = cDateTimeInstanceCache.putIfAbsent(key, pattern);
if (previous != null) {

代码示例来源:origin: looly/hutool

formatter = DateFormat.getTimeInstance(timeStyle.intValue(), locale);
} else if (timeStyle == null) {
  formatter = DateFormat.getDateInstance(dateStyle.intValue(), locale);
} else {
  formatter = DateFormat.getDateTimeInstance(dateStyle.intValue(), timeStyle.intValue(), locale);
pattern = ((SimpleDateFormat) formatter).toPattern();
final String previous = cDateTimeInstanceCache.putIfAbsent(key, pattern);
if (previous != null) {

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

public String calculateTimeOnlyPattern() {
  if (timeOnlyPattern == null) {
    String localePattern = ((SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, calculateLocale(getFacesContext()))).toPattern();
    String userTimePattern = getPattern();
    timeOnlyPattern = localePattern + " " + userTimePattern;
  }
  return timeOnlyPattern;
}

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

public String calculatePattern() {
  String pattern = getPattern();
  Locale locale = calculateLocale(getFacesContext());
  return pattern == null ? ((SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, locale)).toPattern() : pattern;
}

代码示例来源:origin: igniterealtime/Openfire

String pattern = ((SimpleDateFormat)DateFormat.getDateInstance(ds, locale)).toPattern();
format = getInstance(pattern, timeZone, locale);
cDateInstanceCache.put(key, format);

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

DateFormat df = null;
if (type.equals("both")) {
  df = DateFormat.getDateInstance(getStyle(dateStyle), this.getLocale());
  metadata.put(HTML.VALIDATION_METADATA.DATE_STYLE_PATTERN, CalendarUtils.convertPattern(((SimpleDateFormat) df).toPattern()));
  df = DateFormat.getTimeInstance(getStyle(timeStyle), this.getLocale());
  metadata.put(HTML.VALIDATION_METADATA.TIME_STYLE_PATTERN, CalendarUtils.convertPattern(((SimpleDateFormat) df).toPattern()));
  df = DateFormat.getDateInstance(getStyle(dateStyle), this.getLocale());
  metadata.put(HTML.VALIDATION_METADATA.DATE_STYLE_PATTERN, CalendarUtils.convertPattern(((SimpleDateFormat) df).toPattern()));
  metadata.put(HTML.VALIDATION_METADATA.TIME_STYLE_PATTERN, CalendarUtils.convertPattern(((SimpleDateFormat) df).toPattern()));

代码示例来源:origin: camunda/camunda-bpm-platform

String getPattern(Locale locale) {
    DateFormat f = null;
    switch (iType) {
      case DATE:
        f = DateFormat.getDateInstance(iDateStyle, locale);
        break;
      case TIME:
        f = DateFormat.getTimeInstance(iTimeStyle, locale);
        break;
      case DATETIME:
        f = DateFormat.getDateTimeInstance(iDateStyle, iTimeStyle, locale);
        break;
    }
    if (f instanceof SimpleDateFormat == false) {
      throw new IllegalArgumentException("No datetime pattern for locale: " + locale);
    }
    return ((SimpleDateFormat) f).toPattern();
  }
}

代码示例来源:origin: stackoverflow.com

SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.SHORT, l);
String pattern = sdf.toPattern();
String localizedPattern = sdf.toLocalizedPattern()
println "country: " + l.getDisplayName();

相关文章

SimpleDateFormat类方法