本文整理汇总了Java中org.apache.solr.common.util.DateUtil.parseDate方法的典型用法代码示例。如果您正苦于以下问题:Java DateUtil.parseDate方法的具体用法?Java DateUtil.parseDate怎么用?Java DateUtil.parseDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.common.util.DateUtil
的用法示例。
在下文中一共展示了DateUtil.parseDate方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformValue
import org.apache.solr.common.util.DateUtil; //导入方法依赖的package包/类
/**
* Can be used to transform input values based on their {@link org.apache.solr.schema.SchemaField}
* <p/>
* This implementation only formats dates using the {@link org.apache.solr.common.util.DateUtil}.
*
* @param val The value to transform
* @param schFld The {@link org.apache.solr.schema.SchemaField}
* @return The potentially new value.
*/
protected String transformValue(String val, SchemaField schFld) {
String result = val;
if (schFld != null && schFld.getType() instanceof DateField) {
//try to transform the date
try {
Date date = DateUtil.parseDate(val, dateFormats);
DateFormat df = DateUtil.getThreadLocalDateFormat();
result = df.format(date);
} catch (Exception e) {
// Let the specific fieldType handle errors
// throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Invalid value: " + val + " for field: " + schFld, e);
}
}
return result;
}
示例2: getObjectFrom
import org.apache.solr.common.util.DateUtil; //导入方法依赖的package包/类
public static Object getObjectFrom( String val, String type )
{
if( type != null ) {
try {
if( "int".equals( type ) ) return Integer.valueOf( val );
if( "double".equals( type ) ) return Double.valueOf( val );
if( "float".equals( type ) ) return Float.valueOf( val );
if( "date".equals( type ) ) return DateUtil.parseDate(val);
}
catch( Exception ex ) {
throw new SolrException( ErrorCode.BAD_REQUEST,
"Unable to parse "+type+"="+val, ex );
}
}
return val;
}
示例3: castForDescriptor
import org.apache.solr.common.util.DateUtil; //导入方法依赖的package包/类
private static Object castForDescriptor(String s, Class<?> type) {
if(Long.class.isAssignableFrom(type)) {
return Long.valueOf(s);
}
if(Integer.class.isAssignableFrom(type)) {
return Integer.valueOf(s);
}
if(Double.class.isAssignableFrom(type)) {
return Double.valueOf(s);
}
if(Number.class.isAssignableFrom(type)) {
return Float.valueOf(s);
}
if(Boolean.class.isAssignableFrom(type)) {
return Boolean.valueOf(s);
}
if(ZonedDateTime.class.isAssignableFrom(type)) {
return ZonedDateTime.parse(s);
}
if(Date.class.isAssignableFrom(type)) {
try {
return DateUtil.parseDate(s);
} catch (ParseException e) {
log.error("Unable to parse value '{}' to valid Date", s);
throw new RuntimeException(e);
}
}
if(ByteBuffer.class.isAssignableFrom(type)) {
return ByteBuffer.wrap(s.getBytes(UTF_8));
}
return s;
}
示例4: asTimestamp
import org.apache.solr.common.util.DateUtil; //导入方法依赖的package包/类
public Date asTimestamp(Object obj) throws ParseException {
Date ts;
if (obj instanceof String) {
ts = DateUtil.parseDate((String) obj);
} else if (obj instanceof Date) {
ts = (Date)obj;
} else if (obj instanceof Calendar) {
ts = ((Calendar)obj).getTime();
} else if (obj instanceof Long) {
ts = new Date((Long)obj);
} else {
ts = DateUtil.parseDate(obj.toString());
}
return ts;
}
示例5: read
import org.apache.solr.common.util.DateUtil; //导入方法依赖的package包/类
@Override
public Date read( String txt ) {
try {
return DateUtil.parseDate(txt);
}
catch( Exception ex ) {
ex.printStackTrace();
}
return null;
}
示例6: parseDateLenient
import org.apache.solr.common.util.DateUtil; //导入方法依赖的package包/类
/** Parse a date string in the standard format, or any supported by DateUtil.parseDate */
public Date parseDateLenient(String s, SolrQueryRequest req) throws ParseException {
// request could define timezone in the future
try {
return fmtThreadLocal.get().parse(s);
} catch (Exception e) {
return DateUtil.parseDate(s);
}
}
示例7: tryParseDate
import org.apache.solr.common.util.DateUtil; //导入方法依赖的package包/类
private static Date tryParseDate(String query) {
try {
return DateUtil.parseDate(query);
} catch (ParseException e) {
return null;
}
}
示例8: unmarshall
import org.apache.solr.common.util.DateUtil; //导入方法依赖的package包/类
@Override
protected Date unmarshall(String input) {
try {
return DateUtil.parseDate(input);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
示例9: facet
import org.apache.solr.common.util.DateUtil; //导入方法依赖的package包/类
protected FieldFacetKeyBuilder<Date, Date> facet(DateField field) {
Function<String, Date> unmarshallFunc = new Function<String, Date>() {
@Override
public Date apply(String input) {
try {
return DateUtil.parseDate(input);
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
};
return new FieldFacetKeyBuilder<Date, Date>(field, unmarshallFunc, Functions.<Date> identity());
}
示例10: setTimeStamp
import org.apache.solr.common.util.DateUtil; //导入方法依赖的package包/类
public void setTimeStamp(String timeStamp) throws ParseException {
this.timeStamp = DateUtil.parseDate(timeStamp);
// this.timeStamp = DateUtils.parse(timeStamp);
}
示例11: setDateOfBirth
import org.apache.solr.common.util.DateUtil; //导入方法依赖的package包/类
public void setDateOfBirth(String dateOfBirth) throws ParseException{
this.dateOfBirth = DateUtil.parseDate(dateOfBirth);
}
示例12: parseDate
import org.apache.solr.common.util.DateUtil; //导入方法依赖的package包/类
/**
* Returns a formatter that can be use by the current thread if needed to
* convert Date objects to the Internal representation.
*
* @deprecated Use {@link org.apache.solr.common.util.DateUtil#parseDate(String)}
*/
@Deprecated
public static Date parseDate( String d ) throws ParseException
{
return DateUtil.parseDate(d);
}