Save This Page
Home » lucene-2.3.2-src » org.apache » lucene » document » [javadoc | source]
org.apache.lucene.document
public class: DateTools [javadoc | source]
java.lang.Object
   org.apache.lucene.document.DateTools
Provides support for converting dates to strings and vice-versa. The strings are structured so that lexicographic sorting orders them by date, which makes them suitable for use as field values and search terms.

This class also helps you to limit the resolution of your dates. Do not save dates with a finer resolution than you really need, as then RangeQuery and PrefixQuery will require more memory and become slower.

Compared to DateField the strings generated by the methods in this class take slightly more space, unless your selected resolution is set to Resolution.DAY or lower.
Nested Class Summary:
public static class  DateTools.Resolution  Specifies the time granularity. 
Method from org.apache.lucene.document.DateTools Summary:
dateToString,   round,   round,   stringToDate,   stringToTime,   timeToString
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.lucene.document.DateTools Detail:
 public static String dateToString(Date date,
    DateTools.Resolution resolution) 
    Converts a Date to a string suitable for indexing.
 public static Date round(Date date,
    DateTools.Resolution resolution) 
    Limit a date's resolution. For example, the date 2004-09-21 13:50:11 will be changed to 2004-09-01 00:00:00 when using Resolution.MONTH.
 public static long round(long time,
    DateTools.Resolution resolution) 
    Limit a date's resolution. For example, the date 1095767411000 (which represents 2004-09-21 13:50:11) will be changed to 1093989600000 (2004-09-01 00:00:00) when using Resolution.MONTH.
 public static Date stringToDate(String dateString) throws ParseException 
    Converts a string produced by timeToString or dateToString back to a time, represented as a Date object.
 public static long stringToTime(String dateString) throws ParseException 
    Converts a string produced by timeToString or dateToString back to a time, represented as the number of milliseconds since January 1, 1970, 00:00:00 GMT.
 public static String timeToString(long time,
    DateTools.Resolution resolution) 
    Converts a millisecond time to a string suitable for indexing.