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

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

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

DateFormat.parseObject介绍

[英]Parses a date from the specified string starting at the index specified by position. If the string is successfully parsed then the index of the ParsePosition is updated to the index following the parsed text. On error, the index is unchanged and the error index of ParsePosition is set to the index where the error occurred.

By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).
[中]从位置指定的索引处开始分析指定字符串中的日期。如果成功解析字符串,则ParsePosition的索引将更新为解析文本后面的索引。出错时,索引保持不变,ParsePosition的错误索引设置为发生错误的索引。
默认情况下,解析是宽松的:如果输入不是此对象的format方法使用的格式,但仍然可以作为日期进行解析,则解析成功。客户可能会通过调用setLenient(false)来坚持严格遵守格式。

代码示例

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

final Object parsedValue = formatter.parseObject(strValue, pos);
if (pos.getErrorIndex() > -1) {
  throw new ConversionException("Error parsing date '" + value +

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

final Object parsedValue = formatter.parseObject(strValue, pos);
if (pos.getErrorIndex() > -1) {
  throw new ConversionException("Error parsing date '" + value +

代码示例来源:origin: pentaho/pentaho-kettle

dfFormatter = new SimpleDateFormat( sArg2, dfLocale );
 dfFormatter.setTimeZone( tz );
 oRC = dfFormatter.parseObject( sArg1 );
} else {
 throw new RuntimeException( "Locale " + sArg3 + " is not 2 characters long." );

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

return localSimpleDateFormat.get().parseObject(source, pos);

代码示例来源:origin: pentaho/pentaho-kettle

dfFormatter = new SimpleDateFormat( sArg2, dfLocale );
 dfFormatter.setTimeZone( tz );
 oRC = dfFormatter.parseObject( sArg1 );
} else {
 throw Context.reportRuntimeError( "Locale " + sArg3 + " is not 2 characters long." );

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

public Object convertFormValueToModelValue(Object propertyValue) {
 if (propertyValue==null || "".equals(propertyValue)) {
  return null;
 }
 try {
  return dateFormat.parseObject(propertyValue.toString());
 } catch (ParseException e) {
  throw new ProcessEngineException("invalid date value "+propertyValue);
 }
}

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

public Object convertFormValueToModelValue(Object propertyValue) {
 if (propertyValue==null || "".equals(propertyValue)) {
  return null;
 }
 try {
  return dateFormat.parseObject(propertyValue.toString());
 } catch (ParseException e) {
  throw new ProcessEngineException("invalid date value "+propertyValue);
 }
}

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

public TypedValue convertToModelValue(TypedValue propertyValue) {
 Object value = propertyValue.getValue();
 if(value == null) {
  return Variables.dateValue(null, propertyValue.isTransient());
 }
 else if(value instanceof Date) {
  return Variables.dateValue((Date) value, propertyValue.isTransient());
 }
 else if(value instanceof String) {
  String strValue = ((String) value).trim();
  if (strValue.isEmpty()) {
   return Variables.dateValue(null, propertyValue.isTransient());
  }
  try {
   return Variables.dateValue((Date) dateFormat.parseObject(strValue), propertyValue.isTransient());
  } catch (ParseException e) {
   throw new ProcessEngineException("Could not parse value '"+value+"' as date using date format '"+datePattern+"'.");
  }
 }
 else {
  throw new ProcessEngineException("Value '"+value+"' cannot be transformed into a Date.");
 }
}

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

public TypedValue convertToModelValue(TypedValue propertyValue) {
 Object value = propertyValue.getValue();
 if(value == null) {
  return Variables.dateValue(null, propertyValue.isTransient());
 }
 else if(value instanceof Date) {
  return Variables.dateValue((Date) value, propertyValue.isTransient());
 }
 else if(value instanceof String) {
  String strValue = ((String) value).trim();
  if (strValue.isEmpty()) {
   return Variables.dateValue(null, propertyValue.isTransient());
  }
  try {
   return Variables.dateValue((Date) dateFormat.parseObject(strValue), propertyValue.isTransient());
  } catch (ParseException e) {
   throw new ProcessEngineException("Could not parse value '"+value+"' as date using date format '"+datePattern+"'.");
  }
 }
 else {
  throw new ProcessEngineException("Value '"+value+"' cannot be transformed into a Date.");
 }
}

代码示例来源:origin: org.ow2.bonita/bonita-pvm

public Object revert(Object o) {
 try {
  return dateFormat.parseObject((String) o);
 } catch (ParseException e) {
  throw new PvmException("invalid date format in date variable: " + o, e);
 }
}

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
public Object parseObject(final String source, final ParsePosition pos)
{
  return delegate.get().parseObject(source, pos);
}

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
public Object parseObject(final String source) throws ParseException
{
  return delegate.get().parseObject(source);
}

代码示例来源:origin: org.camunda.bpm/camunda-engine

public Object convertFormValueToModelValue(Object propertyValue) {
 if (propertyValue==null || "".equals(propertyValue)) {
  return null;
 }
 try {
  return dateFormat.parseObject(propertyValue.toString());
 } catch (ParseException e) {
  throw new ProcessEngineException("invalid date value "+propertyValue);
 }
}

代码示例来源:origin: org.jbpm/pvm

public Object revert(Object o) {
 try {
  return dateFormat.parseObject((String)o);
 } catch (ParseException e) {
  throw new PvmException("invalid date format in date variable: "+o, e);
 }
}

代码示例来源:origin: com.github.XDean/Java-EX

@Override
public Object parseObject(String source) throws ParseException {
 return get().parseObject(source);
}

代码示例来源:origin: com.github.XDean/Java-EX

@Override
public Object parseObject(String source, ParsePosition pos) {
 return get().parseObject(source, pos);
}

代码示例来源:origin: pentaho/pentaho-reporting

protected Date convertValue( final String text ) {
 if ( StringUtils.isEmpty( text ) ) {
  return null;
 }
 try {
  final Date o = (Date) sdf.parseObject( text );
  // this magic converts the date or number value to the real type.
  // the formatter always returns doubles/bigdecimals or java.util.Dates
  // but we may need sql-dates, long-objects etc ..
  return DateConverter.convertToDateType( o, dateType );
 } catch ( ParseException e ) {
  throw new RuntimeException( "Failed to format object", e );
 }
}

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

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

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

/** {@inheritDoc} */
public Date getDate()
  throws ConversionException {
  if (isEmpty()) {
    return null;
  }
  String str = getText();
  ParsePosition posInOut = new ParsePosition(0);
  Date result = (Date)format.parseObject(str, posInOut);
  if (posInOut.getIndex() == str.length()) {
    return result;
  } else {
    throw new ConversionException();
  }
}

代码示例来源:origin: EvoSuite/evosuite

public Object parseObject(String source, ParsePosition pos) {
  Capturer.capture(Instrumenter.CAPTURE_ID_JAVA_TEXT_DATEFORMAT, this, "parse", "(Ljava/lang/String;Ljava/text/ParsePosition;)Ljava/lang/Object;", new Object[] {source, pos});
  Object ret = super.parseObject(source, pos);
  if(ret instanceof java.util.Date) {
    long time = ((java.util.Date)ret).getTime();
    ret = new Date(time);
  }
  Capturer.enable(Instrumenter.CAPTURE_ID_JAVA_TEXT_DATEFORMAT, this, ret);
  return ret;
}

相关文章