Unosquare
    Show / Hide Table of Contents

    Class DateExtensions

    Provides extension methods for .

    Inheritance
    Object
    DateExtensions
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Swan
    Syntax
    public static class DateExtensions

    Methods

    AsCronCanRun(DateTime, Nullable<Int32>, Nullable<Int32>, Nullable<Int32>, Nullable<Int32>, Nullable<Int32>)

    Compare the Date elements(Months, Days, Hours, Minutes).

    Declaration
    public static bool AsCronCanRun(this DateTime this, int? minute = default(int? ), int? hour = default(int? ), int? dayOfMonth = default(int? ), int? month = default(int? ), int? dayOfWeek = default(int? ))
    Parameters
    Type Name Description
    DateTime this

    The on which this method is called.

    Nullable<Int32> minute

    The minute (0-59).

    Nullable<Int32> hour

    The hour. (0-23).

    Nullable<Int32> dayOfMonth

    The day of month. (1-31).

    Nullable<Int32> month

    The month. (1-12).

    Nullable<Int32> dayOfWeek

    The day of week. (0-6)(Sunday = 0).

    Returns
    Type Description
    Boolean

    Returns true if Months, Days, Hours and Minutes match, otherwise false.

    AsCronCanRun(DateTime, String, String, String, String, String)

    Compare the Date elements(Months, Days, Hours, Minutes).

    Declaration
    public static bool AsCronCanRun(this DateTime this, string minute = "*", string hour = "*", string dayOfMonth = "*", string month = "*", string dayOfWeek = "*")
    Parameters
    Type Name Description
    DateTime this

    The on which this method is called.

    String minute

    The minute (0-59).

    String hour

    The hour. (0-23).

    String dayOfMonth

    The day of month. (1-31).

    String month

    The month. (1-12).

    String dayOfWeek

    The day of week. (0-6)(Sunday = 0).

    Returns
    Type Description
    Boolean

    Returns true if Months, Days, Hours and Minutes match, otherwise false.

    DateRange(DateTime, DateTime)

    Creates a date range.

    Declaration
    public static IEnumerable<DateTime> DateRange(this DateTime startDate, DateTime endDate)
    Parameters
    Type Name Description
    DateTime startDate

    The start date.

    DateTime endDate

    The end date.

    Returns
    Type Description
    IEnumerable<DateTime>

    A sequence of integral numbers within a specified date's range.

    GetDateTimeSpan(DateTime, DateTime)

    Compares a Date to another and returns a DateTimeSpan.

    Declaration
    public static DateTimeSpan GetDateTimeSpan(this DateTime dateStart, DateTime dateEnd)
    Parameters
    Type Name Description
    DateTime dateStart

    The date start.

    DateTime dateEnd

    The date end.

    Returns
    Type Description
    DateTimeSpan

    A DateTimeSpan with the Years, Months, Days, Hours, Minutes, Seconds and Milliseconds between the dates.

    RoundUp(DateTime, TimeSpan)

    Rounds up a date to match a timespan.

    Declaration
    public static DateTime RoundUp(this DateTime date, TimeSpan timeSpan)
    Parameters
    Type Name Description
    DateTime date

    The datetime.

    TimeSpan timeSpan

    The timespan to match.

    Returns
    Type Description
    DateTime

    A new instance of the DateTime structure to the specified datetime and timespan ticks.

    ToDateTime(String)

    Parses a YYYY-MM-DD and optionally it time part, HH:II:SS into a DateTime.

    Declaration
    public static DateTime ToDateTime(this string this)
    Parameters
    Type Name Description
    String this

    The sortable date.

    Returns
    Type Description
    DateTime

    A new instance of the DateTime structure to the specified year, month, day, hour, minute and second.

    ToRfc1123String(DateTime)

    Converts a to the RFC1123 format.

    Declaration
    public static string ToRfc1123String(this DateTime this)
    Parameters
    Type Name Description
    DateTime this

    The on which this method is called.

    Returns
    Type Description
    String

    The string representation of this according to RFC1123.

    Remarks

    If this is not a UTC date / time, its UTC equivalent is converted, leaving this unchanged.

    ToSortableDate(DateTime)

    Converts the date to a YYYY-MM-DD string.

    Declaration
    public static string ToSortableDate(this DateTime this)
    Parameters
    Type Name Description
    DateTime this

    The on which this method is called.

    Returns
    Type Description
    String

    The concatenation of date.Year, date.Month and date.Day.

    ToSortableDateTime(DateTime)

    Converts the date to a YYYY-MM-DD HH:II:SS string.

    Declaration
    public static string ToSortableDateTime(this DateTime this)
    Parameters
    Type Name Description
    DateTime this

    The on which this method is called.

    Returns
    Type Description
    String

    The concatenation of date.Year, date.Month, date.Day, date.Hour, date.Minute and date.Second.

    ToUnixEpochDate(DateTime)

    Get this datetime as a Unix epoch timestamp (seconds since Jan 1, 1970, midnight UTC).

    Declaration
    public static long ToUnixEpochDate(this DateTime this)
    Parameters
    Type Name Description
    DateTime this

    The on which this method is called.

    Returns
    Type Description
    Int64

    Seconds since Unix epoch.

    Comments

    Back to top Copyright © 2017-2019 Unosquare