Show / Hide Table of Contents

    Struct DateTime

    Represents an instant in time, typically expressed as a date and time of day.

    Inherited Members
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetType()
    Namespace: System
    Assembly: mscorlib.dll
    Syntax
    public struct DateTime

    Constructors

    | Improve this Doc View Source

    DateTime(Int32, Int32, Int32)

    Initializes a new instance of the DateTime structure to the specified year, month, and day.

    Declaration
    public DateTime(int year, int month, int day)
    Parameters
    Type Name Description
    Int32 year

    The year (1601 through 3000).

    Int32 month

    The month (1 through 12).

    Int32 day

    The day (1 through the number of days in month).

    | Improve this Doc View Source

    DateTime(Int32, Int32, Int32, Int32, Int32, Int32)

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

    Declaration
    public DateTime(int year, int month, int day, int hour, int minute, int second)
    Parameters
    Type Name Description
    Int32 year

    The year (1601 through 3000).

    Int32 month

    The month (1 through 12).

    Int32 day

    The day (1 through the number of days in month).

    Int32 hour

    The hours (0 through 23).

    Int32 minute

    The minutes (0 through 59).

    Int32 second

    The seconds (0 through 59).

    DateTime(Int32, Int32, Int32, Int32, Int32, Int32, Int32)

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

    Declaration
    public extern DateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
    Parameters
    Type Name Description
    Int32 year

    The year (1601 through 3000).

    Int32 month

    The month (1 through 12).

    Int32 day

    The day (1 through the number of days in month).

    Int32 hour

    The hours (0 through 23).

    Int32 minute

    The minutes (0 through 59).

    Int32 second

    The seconds (0 through 59).

    Int32 millisecond

    The milliseconds (0 through 999).

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    Any parameter out of the accepted ranges

    | Improve this Doc View Source

    DateTime(Int64)

    Initializes a new instance of the DateTime structure to a specified number of ticks.

    Declaration
    public DateTime(long ticks)
    Parameters
    Type Name Description
    Int64 ticks

    A date and time expressed in the number of 100-nanosecond intervals.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    ticks - Ticks must be between MinValue and MaxValue.

    | Improve this Doc View Source

    DateTime(Int64, DateTimeKind)

    Initializes a new instance of the DateTime structure to a specified number of ticks and to Coordinated Universal Time (UTC).

    Declaration
    public DateTime(long ticks, DateTimeKind kind)
    Parameters
    Type Name Description
    Int64 ticks

    A date and time expressed in the number of 100-nanosecond intervals.

    DateTimeKind kind

    One of the enumeration values that indicates whether ticks specifies a local time, Coordinated Universal Time (UTC), or neither.

    Remarks

    nanoFramework doesn't support local time, only UTC, so it's not possible to specify Local.

    Fields

    | Improve this Doc View Source

    MaxValue

    Represents the largest possible value of DateTime. This field is read-only.

    Declaration
    public static readonly DateTime MaxValue
    Field Value
    Type Description
    DateTime
    Remarks

    The value of this constant is equivalent to 23:59:59.9999999, December 31, 3000. This value is specific to nanoFramework. .NET equivalent is 23:59:59.9999999 UTC, December 31, 9999 in the Gregorian calendar.

    | Improve this Doc View Source

    MinValue

    Represents the smallest possible value of DateTime. This field is read-only.

    Declaration
    public static readonly DateTime MinValue
    Field Value
    Type Description
    DateTime
    Remarks

    The value of this constant is equivalent to 00:00:00.0000000, January 1, 1601. This value is specific to nanoFramework. .NET equivalent is 00:00:00.0000000 UTC, January 1, 0001, in the Gregorian calendar.

    | Improve this Doc View Source

    UnixEpoch

    Represents the Unix Epoch value. This field is read-only.

    Declaration
    public static readonly DateTime UnixEpoch
    Field Value
    Type Description
    DateTime
    Remarks

    The value of this constant is equivalent to the DateTime corresponding to 1970-01-01T00:00:00Z (January 1, 1970, at 12:00 AM UTC). This value is specific to nanoFramework.

    Properties

    | Improve this Doc View Source

    Date

    Gets the date component of this instance.

    Declaration
    public readonly DateTime Date { get; }
    Property Value
    Type Description
    DateTime

    A new object with the same date as this instance, and the time value set to 12:00:00 midnight (00:00:00).

    | Improve this Doc View Source

    Day

    Gets the day of the month represented by this instance.

    Declaration
    public readonly int Day { get; }
    Property Value
    Type Description
    Int32

    The day component, expressed as a value between 1 and 31.

    | Improve this Doc View Source

    DayOfWeek

    Gets the day of the week represented by this instance.

    Declaration
    public readonly DayOfWeek DayOfWeek { get; }
    Property Value
    Type Description
    DayOfWeek

    An enumerated constant that indicates the day of the week of this DateTime value.

    | Improve this Doc View Source

    DayOfYear

    Gets the day of the year represented by this instance.

    Declaration
    public readonly int DayOfYear { get; }
    Property Value
    Type Description
    Int32

    The day of the year, expressed as a value between 1 and 366.

    | Improve this Doc View Source

    Hour

    Gets the hour component of the date represented by this instance.

    Declaration
    public readonly int Hour { get; }
    Property Value
    Type Description
    Int32

    The hour component, expressed as a value between 0 and 23.

    | Improve this Doc View Source

    Kind

    Gets a value that indicates whether the time represented by this instance is based on local time, Coordinated Universal Time (UTC), or neither.

    Declaration
    public readonly DateTimeKind Kind { get; }
    Property Value
    Type Description
    DateTimeKind

    One of the enumeration values that indicates what the current time represents.

    Remarks

    Despite the default in the full .NET Framework is Local this won't never happen because nanoFramework only supports UTC time.

    | Improve this Doc View Source

    Millisecond

    Gets the milliseconds component of the date represented by this instance.

    Declaration
    public readonly int Millisecond { get; }
    Property Value
    Type Description
    Int32

    The milliseconds component, expressed as a value between 0 and 999.

    | Improve this Doc View Source

    Minute

    Gets the minute component of the date represented by this instance.

    Declaration
    public readonly int Minute { get; }
    Property Value
    Type Description
    Int32

    The minute component, expressed as a value between 0 and 59.

    | Improve this Doc View Source

    Month

    Gets the month component of the date represented by this instance.

    Declaration
    public readonly int Month { get; }
    Property Value
    Type Description
    Int32

    The month component, expressed as a value between 1 and 12.

    | Improve this Doc View Source

    Second

    Gets the seconds component of the date represented by this instance.

    Declaration
    public readonly int Second { get; }
    Property Value
    Type Description
    Int32

    The seconds component, expressed as a value between 0 and 59.

    | Improve this Doc View Source

    Ticks

    Gets the number of ticks that represent the date and time of this instance.

    Declaration
    public readonly long Ticks { get; }
    Property Value
    Type Description
    Int64

    The number of ticks that represent the date and time of this instance. The value is between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks

    | Improve this Doc View Source

    TimeOfDay

    Gets the time of day for this instance.

    Declaration
    public readonly TimeSpan TimeOfDay { get; }
    Property Value
    Type Description
    TimeSpan

    A time interval that represents the fraction of the day that has elapsed since midnight.

    | Improve this Doc View Source

    Today

    Gets the current date.

    Declaration
    public static readonly DateTime Today { get; }
    Property Value
    Type Description
    DateTime

    An object that is set to today's date, with the time component set to 00:00:00.

    | Improve this Doc View Source

    UtcNow

    Gets a DateTime object that is set to the current date and time on this computer, expressed as the Coordinated Universal Time (UTC).

    Declaration
    public static readonly DateTime UtcNow { get; }
    Property Value
    Type Description
    DateTime

    An object whose value is the current UTC date and time.

    | Improve this Doc View Source

    Year

    Gets the year component of the date represented by this instance.

    Declaration
    public readonly int Year { get; }
    Property Value
    Type Description
    Int32

    The year, between 1 and 9999.

    Methods

    | Improve this Doc View Source

    Add(TimeSpan)

    Returns a new DateTime that adds the value of the specified TimeSpan to the value of this instance.

    Declaration
    public DateTime Add(TimeSpan val)
    Parameters
    Type Name Description
    TimeSpan val

    A positive or negative time interval.

    Returns
    Type Description
    DateTime

    An object whose value is the sum of the date and time represented by this instance and the time interval represented by val.

    | Improve this Doc View Source

    AddDays(Double)

    Returns a new DateTime that adds the specified number of days to the value of this instance.

    Declaration
    public DateTime AddDays(double val)
    Parameters
    Type Name Description
    Double val

    A number of whole and fractional days. The val parameter can be negative or positive.

    Returns
    Type Description
    DateTime

    An object whose value is the sum of the date and time represented by this instance and the number of days represented by val.

    | Improve this Doc View Source

    AddHours(Double)

    Returns a new DateTime that adds the specified number of hours to the value of this instance.

    Declaration
    public DateTime AddHours(double val)
    Parameters
    Type Name Description
    Double val

    A number of whole and fractional hours. The val parameter can be negative or positive.

    Returns
    Type Description
    DateTime

    An object whose value is the sum of the date and time represented by this instance and the number of hours represented by val.

    | Improve this Doc View Source

    AddMilliseconds(Double)

    Returns a new DateTime that adds the specified number of milliseconds to the value of this instance.

    Declaration
    public DateTime AddMilliseconds(double val)
    Parameters
    Type Name Description
    Double val

    A number of whole and fractional milliseconds. The val parameter can be negative or positive. Note that this value is rounded to the nearest integer.

    Returns
    Type Description
    DateTime

    An object whose value is the sum of the date and time represented by this instance and the number of milliseconds represented by val.

    | Improve this Doc View Source

    AddMinutes(Double)

    Returns a new DateTime that adds the specified number of minutes to the value of this instance.

    Declaration
    public DateTime AddMinutes(double val)
    Parameters
    Type Name Description
    Double val

    A number of whole and fractional minutes. The val parameter can be negative or positive.

    Returns
    Type Description
    DateTime

    An object whose value is the sum of the date and time represented by this instance and the number of minutes represented by val.

    | Improve this Doc View Source

    AddSeconds(Double)

    Returns a new DateTime that adds the specified number of seconds to the value of this instance.

    Declaration
    public DateTime AddSeconds(double val)
    Parameters
    Type Name Description
    Double val

    A number of whole and fractional seconds. The val parameter can be negative or positive.

    Returns
    Type Description
    DateTime

    An object whose value is the sum of the date and time represented by this instance and the number of seconds represented by val.

    | Improve this Doc View Source

    AddTicks(Int64)

    Returns a new DateTime that adds the specified number of ticks to the value of this instance.

    Declaration
    public DateTime AddTicks(long val)
    Parameters
    Type Name Description
    Int64 val

    A number of 100-nanosecond ticks. The val parameter can be positive or negative.

    Returns
    Type Description
    DateTime

    An object whose value is the sum of the date and time represented by this instance and the time represented by val.

    | Improve this Doc View Source

    Compare(DateTime, DateTime)

    Compares two instances of DateTime and returns an integer that indicates whether the first instance is earlier than, the same as, or later than the second instance.

    Declaration
    public static int Compare(DateTime t1, DateTime t2)
    Parameters
    Type Name Description
    DateTime t1

    The first object to compare.

    DateTime t2

    The second object to compare.

    Returns
    Type Description
    Int32

    A signed number indicating the relative values of t1 and t2.

    | Improve this Doc View Source

    CompareTo(Object)

    Compares the value of this instance to a specified object that contains a specified DateTime value, and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified DateTime value.

    Declaration
    public int CompareTo(object val)
    Parameters
    Type Name Description
    Object val

    A boxed object to compare, or null reference (Nothing in Visual Basic).

    Returns
    Type Description
    Int32

    A signed number indicating the relative values of this instance and value.

    DaysInMonth(Int32, Int32)

    Returns the number of days in the specified month and year.

    Declaration
    public static extern int DaysInMonth(int year, int month)
    Parameters
    Type Name Description
    Int32 year

    The year.

    Int32 month

    The month (a number ranging from 1 to 12).

    Returns
    Type Description
    Int32

    The number of days in month for the specified year. For example, if month equals 2 for February, the return value is 28 or 29 depending upon whether year is a leap year.

    | Improve this Doc View Source

    Equals(DateTime, DateTime)

    Returns a value indicating whether two DateTime instances have the same date and time value.

    Declaration
    public static bool Equals(DateTime t1, DateTime t2)
    Parameters
    Type Name Description
    DateTime t1

    The first object to compare.

    DateTime t2

    The second object to compare.

    Returns
    Type Description
    Boolean

    true if the two values are equal; otherwise, false.

    | Improve this Doc View Source

    Equals(Object)

    Returns a value indicating whether this instance is equal to a specified object.

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    Object obj

    The object to compare to this instance.

    Returns
    Type Description
    Boolean

    true if obj is an instance of DateTime and equals the value of this instance; otherwise, false.

    Overrides
    ValueType.Equals(Object)
    | Improve this Doc View Source

    FromUnixTimeSeconds(Int64)

    Converts a Unix time expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z to a DateTime value.

    Declaration
    public static DateTime FromUnixTimeSeconds(long seconds)
    Parameters
    Type Name Description
    Int64 seconds

    A Unix time, expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z (January 1, 1970, at 12:00 AM UTC). For Unix times before this date, its value is negative.

    Returns
    Type Description
    DateTime

    A date and time value that represents the same moment in time as the Unix time.

    Remarks

    This method is exclusive of nanoFramework.

    | Improve this Doc View Source

    GetHashCode()

    Returns the hash code for this instance.

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    Int32

    A 32-bit signed integer hash code.

    Overrides
    Object.GetHashCode()
    | Improve this Doc View Source

    Parse(String)

    Converts the string representation of a date and time to its DateTime equivalent by using the conventions of the current culture.

    Declaration
    public static DateTime Parse(string s)
    Parameters
    Type Name Description
    String s

    A string that contains a date and time to convert. See The string to parse for more information.

    Returns
    Type Description
    DateTime

    An object that is equivalent to the date and time contained in s.

    Remarks

    .NET nanoFramework doesn't support local times so converted values will always have Kind set to Utc.

    This attempts to parse s by using the formatting conventions of Invariant Culture.

    Exceptions
    Type Condition
    ArgumentNullException

    s is null.

    FormatException

    Failed to parse s.

    | Improve this Doc View Source

    Subtract(DateTime)

    Subtracts the specified date and time from this instance.

    Declaration
    public TimeSpan Subtract(DateTime val)
    Parameters
    Type Name Description
    DateTime val

    The date and time value to subtract.

    Returns
    Type Description
    TimeSpan

    A time interval that is equal to the date and time represented by this instance minus the date and time represented by val.

    | Improve this Doc View Source

    Subtract(TimeSpan)

    Subtracts the specified duration from this instance.

    Declaration
    public DateTime Subtract(TimeSpan val)
    Parameters
    Type Name Description
    TimeSpan val

    The time interval to subtract.

    Returns
    Type Description
    DateTime

    An object that is equal to the date and time represented by this instance minus the time interval represented by val.

    | Improve this Doc View Source

    ToString()

    Converts the value of the current DateTime object to its equivalent string representation.

    Declaration
    public override string ToString()
    Returns
    Type Description
    String

    A string representation of the value of the current DateTime object.

    Overrides
    Object.ToString()
    | Improve this Doc View Source

    ToString(String)

    Converts the value of the current DateTime object to its equivalent string representation using the specified format.

    Declaration
    public string ToString(string format)
    Parameters
    Type Name Description
    String format

    A standard or custom date and time format string (see Remarks).

    Returns
    Type Description
    String

    A string representation of value of the current DateTime object as specified by format.

    | Improve this Doc View Source

    ToUnixTimeSeconds()

    Returns the number of seconds that have elapsed since 1970-01-01T00:00:00Z.

    Declaration
    public long ToUnixTimeSeconds()
    Returns
    Type Description
    Int64

    The number of seconds that have elapsed since 1970-01-01T00:00:00Z.

    Remarks

    Unix time represents the number of seconds that have elapsed since 1970-01-01T00:00:00Z (January 1, 1970, at 12:00 AM UTC). It does not take leap seconds into account.

    This method is exclusive of nanoFramework.

    | Improve this Doc View Source

    TryParse(String, out DateTime)

    Converts the specified string representation of a date and time to its DateTime equivalent and returns a value that indicates whether the conversion succeeded.

    Declaration
    public static bool TryParse(string s, out DateTime result)
    Parameters
    Type Name Description
    String s

    A string containing a date and time to convert.

    DateTime result

    When this method returns, contains the DateTime value equivalent to the date and time contained in s, if the conversion succeeded, or MinValue if the conversion failed. The conversion fails if the s parameter is null, is an Empty, or does not contain a valid string representation of a date and time. This parameter is passed uninitialized.

    Returns
    Type Description
    Boolean

    true if the s parameter was converted successfully; otherwise, false.

    Remarks

    The TryParse(String, out DateTime) method is similar to the Parse(String) method, except that the TryParse(String, out DateTime) method does not throw an exception if the conversion fails.

    The string s is parsed using formatting information of the Invariant Culture.

    Operators

    | Improve this Doc View Source

    Addition(DateTime, TimeSpan)

    Adds a specified time interval to a specified date and time, yielding a new date and time.

    Declaration
    public static DateTime operator +(DateTime d, TimeSpan t)
    Parameters
    Type Name Description
    DateTime d

    The date and time value to add.

    TimeSpan t

    The time interval to add.

    Returns
    Type Description
    DateTime

    An object that is the sum of the values of d and t.

    | Improve this Doc View Source

    Equality(DateTime, DateTime)

    Determines whether two specified instances of DateTime are equal.

    Declaration
    public static bool operator ==(DateTime d1, DateTime d2)
    Parameters
    Type Name Description
    DateTime d1

    The first object to compare.

    DateTime d2

    The second object to compare.

    Returns
    Type Description
    Boolean

    true if d1 and d2 represent the same date and time; otherwise, false.

    | Improve this Doc View Source

    GreaterThan(DateTime, DateTime)

    Determines whether one specified DateTime is greater than another specified DateTime.

    Declaration
    public static bool operator>(DateTime t1, DateTime t2)
    Parameters
    Type Name Description
    DateTime t1

    The first object to compare.

    DateTime t2

    The second object to compare.

    Returns
    Type Description
    Boolean

    true if t1 is greater than t2; otherwise, false.

    | Improve this Doc View Source

    GreaterThanOrEqual(DateTime, DateTime)

    Determines whether one specified DateTime is greater than or equal to another specified DateTime.

    Declaration
    public static bool operator >=(DateTime t1, DateTime t2)
    Parameters
    Type Name Description
    DateTime t1

    The first object to compare.

    DateTime t2

    The second object to compare.

    Returns
    Type Description
    Boolean

    true if t1 is greater than or equal to t2; otherwise, false.

    | Improve this Doc View Source

    Inequality(DateTime, DateTime)

    Determines whether two specified instances of DateTime are not equal.

    Declaration
    public static bool operator !=(DateTime t1, DateTime t2)
    Parameters
    Type Name Description
    DateTime t1

    The first object to compare.

    DateTime t2

    The second object to compare.

    Returns
    Type Description
    Boolean

    true if t1 and t2 do not represent the same date and time; otherwise, false.

    | Improve this Doc View Source

    LessThan(DateTime, DateTime)

    Determines whether one specified DateTime is less than another specified DateTime.

    Declaration
    public static bool operator <(DateTime t1, DateTime t2)
    Parameters
    Type Name Description
    DateTime t1

    The first object to compare.

    DateTime t2

    The second object to compare.

    Returns
    Type Description
    Boolean

    true if t1 is less than t2; otherwise, false.

    | Improve this Doc View Source

    LessThanOrEqual(DateTime, DateTime)

    Determines whether one specified DateTime is less than or equal to another specified DateTime.

    Declaration
    public static bool operator <=(DateTime t1, DateTime t2)
    Parameters
    Type Name Description
    DateTime t1

    The first object to compare.

    DateTime t2

    The second object to compare.

    Returns
    Type Description
    Boolean

    true if t1 is less than or equal to t2; otherwise, false.

    | Improve this Doc View Source

    Subtraction(DateTime, DateTime)

    Subtracts a specified date and time from another specified date and time and returns a time interval.

    Declaration
    public static TimeSpan operator -(DateTime d1, DateTime d2)
    Parameters
    Type Name Description
    DateTime d1

    The date and time value to subtract from (the minuend).

    DateTime d2

    The date and time value to subtract (the subtrahend).

    Returns
    Type Description
    TimeSpan

    The time interval between d1 and d2; that is, d1 minus d2.

    | Improve this Doc View Source

    Subtraction(DateTime, TimeSpan)

    Subtracts a specified time interval from a specified date and time and returns a new date and time.

    Declaration
    public static DateTime operator -(DateTime d, TimeSpan t)
    Parameters
    Type Name Description
    DateTime d

    The date and time value to subtract from.

    TimeSpan t

    The time interval to subtract.

    Returns
    Type Description
    DateTime

    An object whose value is the value of d minus the value of t.

    • Improve this Doc
    • View Source
    Back to top Copyright © 2018 nanoFramework Contributors
    Generated by DocFX