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

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

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

SimpleDateFormat.getDateInstance介绍

暂无

代码示例

代码示例来源:origin: scwang90/SmartRefreshLayout

ItemAdapter(Context context) {
  mInflater = LayoutInflater.from(context);
  dateFormat = SimpleDateFormat.getDateInstance(DateFormat.DEFAULT, Locale.ENGLISH);
}

代码示例来源:origin: rey5137/material

private boolean isMonthFirst(){
  SimpleDateFormat format = (SimpleDateFormat)SimpleDateFormat.getDateInstance(SimpleDateFormat.FULL);
  String pattern = format.toLocalizedPattern();
  return pattern.indexOf("M") < pattern.indexOf("d");
}

代码示例来源:origin: rey5137/material

@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);
}

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

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);
}

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

@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;
}

代码示例来源:origin: phajduk/RxValidator

public AgeValidator() {
 message = DEFAULT_MESSAGE;
 age = DEFAULT_AGE;
 sdf = SimpleDateFormat.getDateInstance();
}

代码示例来源:origin: te-con/ehour

/**
 * 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();
}

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

/**
 * 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);
}

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

/**
 * 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);
}

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

/**
 * 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);
}

代码示例来源:origin: FudanSELab/train-ticket

private void changeShowDate() {
  String dateStr = SimpleDateFormat.getDateInstance().format(startDate.getTime());
  // Dec 19, 2018
  startDateBtn.setText(dateStr);
}

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

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));
}

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

/**
 * 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);
}

代码示例来源:origin: com.liferay.faces/liferay-faces-alloy

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();
}

代码示例来源:origin: com.liferay.faces/com.liferay.faces.alloy

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();
  }
}

代码示例来源:origin: ycuwq/DatePicker

/**
 * Gets date.
 *
 * @return the date
 */
public String getDate() {
  DateFormat format = SimpleDateFormat.getDateInstance();
  return getDate(format);
}

代码示例来源:origin: matburt/mobileorg-android

/**
 * 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());
}

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

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);
}

代码示例来源:origin: com.vaadin/vaadin-compatibility-server

private DateFormat getWeeklyCaptionFormatter() {
  if (weeklyCaptionFormat != null) {
    return new SimpleDateFormat(weeklyCaptionFormat, getLocale());
  } else {
    return SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT,
        getLocale());
  }
}

代码示例来源:origin: brarcher/budget-watch

@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();
}

相关文章

SimpleDateFormat类方法