感谢楼上的回复,其实我要求的是自动转换(某些情况下并不清楚某个field是什么类型):
-
- long dt = new Date().getTime()
- document.add(new NumericField("date",Field.Store.YES,true).setLongValue(dt));
-
-
- Fieldable f=doc.getFieldable("date");
- if(f instanceof NumericField )
- {
- NumericField nf=(NumericField )f;
- Long date=(Long)nf.getNumericValue();
- datestr = timeformat.format(new Date(date));
- }
- else
- {
- ...
- }
//建立
long dt = new Date().getTime()
document.add(new NumericField("date",Field.Store.YES,true).setLongValue(dt));
//读取
Fieldable f=doc.getFieldable("date");
if(f instanceof NumericField )
{
NumericField nf=(NumericField )f;
Long date=(Long)nf.getNumericValue();
datestr = timeformat.format(new Date(date));
}
else
{
...
}