java.text.DateFormat.getTimeInstance()方法的使用及代码示例

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

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

DateFormat.getTimeInstance介绍

[英]Returns a DateFormat instance for formatting and parsing time values in the DEFAULT style for the default locale.
[中]返回一个DateFormat实例,用于以默认语言环境的默认样式格式化和分析时间值。

代码示例

代码示例来源: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

DateFormat df = DateFormat.getTimeInstance();
df.setTimeZone(TimeZone.getTimeZone("gmt"));
String gmtTime = df.format(new Date());

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

DateFormat.getDateInstance().format(new Date(0));  
 DateFormat.getDateTimeInstance().format(new Date(0));  
 DateFormat.getTimeInstance().format(new Date(0));

代码示例来源:origin: pentaho/mondrian

java.text.DateFormat.getDateInstance(
    java.text.DateFormat.SHORT, locale);
final String dateValue = dateFormat.format(date); // "12/31/69"
String dateSeparator = dateValue.substring(2, 3); // "/"
  java.text.DateFormat.getTimeInstance(
    java.text.DateFormat.SHORT, locale);
final String timeValue = timeFormat.format(date); // "12:00:00"
String timeSeparator = timeValue.substring(2, 3); // ":"

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

return DateFormat.getDateTimeInstance().format((Date) o);
  return DateFormat.getTimeInstance().format((Date) o);
return DateFormat.getInstance().format((Date) o);

代码示例来源: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: stackoverflow.com

if( timeFormat == null ) timeFormat = DateFormat.getTimeInstance( DateFormat.SHORT );
updateTextFieldFormat();
newPanel.add(new JLabel( "Time:" ) );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DateTimePicker dateTimePicker = new DateTimePicker();
dateTimePicker.setFormats( DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.MEDIUM ) );
dateTimePicker.setTimeFormat( DateFormat.getTimeInstance( DateFormat.MEDIUM ) );

代码示例来源:origin: openmrs/openmrs-core

dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
} else if (type == FORMAT_TYPE.TIME) {
  dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
} else {
  dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
return dateFormat.format(date);

代码示例来源:origin: org.codehaus.groovy/groovy

@Deprecated
public static String getTimeString(Date self) {
  return DateFormat.getTimeInstance(DateFormat.MEDIUM).format(self);
}

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

public void updateLabels() {
  Date today = new Date();
  label.setText(DateFormat.getDateInstance(DateFormat.FULL).format(today));
  label2.setText(DateFormat.getTimeInstance().format(today));
}

代码示例来源: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: stackoverflow.com

@Override
public void onClick(View view){

 if(view.getId()==R.id.btngo)
 mytime = java.text.DateFormat.getTimeInstance().format(Calendar.getInstance().getTime());

// date
 mydate =java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
 etdate.setText(mydate); 
 ettime.setText(mytime);
}
}

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

case 1: // date
  if (ch == '}') {
    return type == 1 ? DateFormat.getDateInstance(
        DateFormat.DEFAULT, locale) : DateFormat
        .getTimeInstance(DateFormat.DEFAULT, locale);
      .getDateInstance(dateStyle, locale) : DateFormat
      .getTimeInstance(dateStyle, locale);
case 2: // number
  if (ch == '}') {

代码示例来源:origin: haraldk/TwelveMonkeys

@Test
public void testToDateWithFormat() {
  Calendar cal = new GregorianCalendar();
  cal.clear();
  cal.set(1976, 2, 16); // Month is 0-based
  Date date = StringUtil.toDate("16.03.1976", new SimpleDateFormat("dd.MM.yyyy"));
  assertNotNull(date);
  assertEquals(cal.getTime(), date);
  cal.clear();
  cal.set(2004, 4, 13, 23, 51);
  date = StringUtil.toDate("13.5.04 23:51",
               DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, new Locale("no", "NO")));
  assertNotNull(date);
  assertEquals(cal.getTime(), date);
  cal.clear();
  cal.set(Calendar.HOUR, 1);
  cal.set(Calendar.MINUTE, 2);
  date = StringUtil.toDate("1:02 am",
               DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US));
  assertNotNull(date);
  assertEquals(cal.getTime(), date);
}

代码示例来源:origin: pentaho/mondrian

return DateFormat.getDateInstance(DateFormat.LONG).format(date);
return DateFormat.getDateInstance(DateFormat.SHORT).format(date);
return DateFormat.getTimeInstance(DateFormat.LONG).format(date);
return DateFormat.getTimeInstance(DateFormat.SHORT).format(date);
return DateFormat.getDateTimeInstance().format(date);

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

/**
 * Formats a Date object to return a time using the global locale.
 *
 * @param date the Date to format.
 * @return a String representing the time.
 */
public static String formatTime(Date date) {
  if (timeFormat == null) {
    if (properties != null) {
      timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, getLocale());
      timeFormat.setTimeZone(getTimeZone());
    }
    else {
      DateFormat instance = DateFormat.getTimeInstance(DateFormat.SHORT, getLocale());
      instance.setTimeZone(getTimeZone());
      return instance.format(date);
    }
  }
  return timeFormat.format(date);
}

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

Date today = new Date(); // current time
 String date[] = DateFormat.getDateInstance().format(today).split(",");
 String month = date[0]; // get only date 
 String time = DateFormat.getTimeInstance().format(today); 
 // split the time if you need to remove PM/AM

代码示例来源: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

mytime = java.text.DateFormat.getTimeInstance().format(Calendar.getInstance().getTime());

// date
mydate =java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());

代码示例来源: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()));
  df = DateFormat.getTimeInstance(getStyle(timeStyle), this.getLocale());
  metadata.put(HTML.VALIDATION_METADATA.TIME_STYLE_PATTERN, CalendarUtils.convertPattern(((SimpleDateFormat) df).toPattern()));

相关文章