Show / Hide Table of Contents

    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 TermRangeQuery and PrefixQuery will require more memory and become slower.

    Another approach is NumericUtils, which provides a sortable binary representation (prefix encoded) of numeric values, which date/time are.

    For indexing a , just get the and index this as a numeric value with Int64Field and use NumericRangeQuery<T> to query it.

    Inheritance
    System.Object
    DateTools
    Namespace: Lucene.Net.Documents
    Assembly: Lucene.Net.dll
    Syntax
    public static class DateTools : object

    Methods

    | Improve this Doc View Source

    DateToString(DateTime, DateTools.Resolution)

    Converts a to a string suitable for indexing.

    Declaration
    public static string DateToString(DateTime date, DateTools.Resolution resolution)
    Parameters
    Type Name Description
    DateTime date

    the date to be converted

    DateTools.Resolution resolution

    the desired resolution, see Round(DateTime, DateTools.Resolution)

    Returns
    Type Description
    System.String

    a string in format yyyyMMddHHmmssSSS or shorter, depending on resolution; using GMT as timezone

    | Improve this Doc View Source

    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
    DateTime date

    the date to be rounded

    DateTools.Resolution resolution

    The desired resolution of the date to be returned

    Returns
    Type Description
    DateTime

    the date with all values more precise than resolution set to 0 or 1

    | Improve this Doc View Source

    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.Int64 time

    the time to be rounded

    DateTools.Resolution resolution

    The desired resolution of the date to be returned

    Returns
    Type Description
    System.Int64

    the date with all values more precise than resolution set to 0 or 1, expressed as milliseconds since January 1, 1970, 00:00:00 GMT (also known as the "epoch")

    | Improve this Doc View Source

    StringToDate(String)

    Converts a string produced by TimeToString(Int64, DateTools.Resolution) or DateToString(DateTime, DateTools.Resolution) back to a time, represented as a object.

    Declaration
    public static DateTime StringToDate(string dateString)
    Parameters
    Type Name Description
    System.String dateString

    the date string to be converted

    Returns
    Type Description
    DateTime

    the parsed time as a object

    | Improve this Doc View Source

    StringToTime(String)

    Converts a string produced by TimeToString(Int64, DateTools.Resolution) or DateToString(DateTime, DateTools.Resolution) back to a time, represented as the number of milliseconds since January 1, 1970, 00:00:00 GMT (also known as the "epoch").

    Declaration
    public static long StringToTime(string dateString)
    Parameters
    Type Name Description
    System.String dateString

    the date string to be converted

    Returns
    Type Description
    System.Int64

    the number of milliseconds since January 1, 1970, 00:00:00 GMT (also known as the "epoch")

    | Improve this Doc View Source

    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.Int64 time

    the date expressed as milliseconds since January 1, 1970, 00:00:00 GMT (also known as the "epoch")

    DateTools.Resolution resolution

    the desired resolution, see Round(Int64, DateTools.Resolution)

    Returns
    Type Description
    System.String

    a string in format yyyyMMddHHmmssSSS or shorter, depending on resolution; using GMT as timezone

    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)