Class 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
Term
Another approach is Numeric
For indexing a
Inheritance
Namespace: Lucene.Net.Documents
Assembly: Lucene.Net.dll
Syntax
public static class DateTools : object
Methods
| Improve this Doc View SourceDateToString(DateTime, DateTools.Resolution)
Converts a
Declaration
public static string DateToString(DateTime date, DateTools.Resolution resolution)
Parameters
Type | Name | Description |
---|---|---|
Date |
date | the date to be converted |
Date |
resolution | the desired resolution, see
Round(Date |
Returns
Type | Description |
---|---|
System. |
a string in format |
Round(DateTime, DateTools.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
MONTH.
Declaration
public static DateTime Round(DateTime date, DateTools.Resolution resolution)
Parameters
Type | Name | Description |
---|---|---|
Date |
date | the date to be rounded |
Date |
resolution | The desired resolution of the date to be returned |
Returns
Type | Description |
---|---|
Date |
the date with all values more precise than |
Round(Int64, DateTools.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
MONTH.
Declaration
public static long Round(long time, DateTools.Resolution resolution)
Parameters
Type | Name | Description |
---|---|---|
System. |
time | the time to be rounded |
Date |
resolution | The desired resolution of the date to be returned |
Returns
Type | Description |
---|---|
System. |
the date with all values more precise than |
StringToDate(String)
Converts a string produced by Time
Declaration
public static DateTime StringToDate(string dateString)
Parameters
Type | Name | Description |
---|---|---|
System. |
dateString | the date string to be converted |
Returns
Type | Description |
---|---|
Date |
the parsed time as a |
StringToTime(String)
Converts a string produced by Time
Declaration
public static long StringToTime(string dateString)
Parameters
Type | Name | Description |
---|---|---|
System. |
dateString | the date string to be converted |
Returns
Type | Description |
---|---|
System. |
the number of milliseconds since January 1, 1970, 00:00:00 GMT (also known as the "epoch") |
TimeToString(Int64, DateTools.Resolution)
Converts a millisecond time to a string suitable for indexing.
Declaration
public static string TimeToString(long time, DateTools.Resolution resolution)
Parameters
Type | Name | Description |
---|---|---|
System. |
time | the date expressed as milliseconds since January 1, 1970, 00:00:00 GMT (also known as the "epoch") |
Date |
resolution | the desired resolution, see
Round(Int64, Date |
Returns
Type | Description |
---|---|
System. |
a string in format |