C# DateTimeOffset Date

Description

DateTimeOffset Date gets a DateTime value that represents the date component of the current DateTimeOffset object.

Syntax

DateTimeOffset.Date has the following syntax.


public DateTime Date { get; }

Example

The following example retrieves the value of the Date property for a specific date. It then displays that value to the console using some standard and custom date-only format specifiers.


/*from ww w. ja va2  s  .  c om*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
        
    DateTimeOffset thisDate = new DateTimeOffset(2014, 3, 17, 1, 32, 0, new TimeSpan(-5, 0, 0));
    string fmt;                      // format specifier 
    
    fmt = "D";
    Console.WriteLine("'{0}' format specifier: {1}",  
                      fmt, thisDate.Date.ToString(fmt));
    
    fmt = "d";
    Console.WriteLine("'{0}' format specifier: {1}",  
                      fmt, thisDate.Date.ToString(fmt));
    
    fmt = "Y";
    Console.WriteLine("'{0}' format specifier: {1}",  
                      fmt, thisDate.Date.ToString(fmt));
    
    fmt = "dd MMM yyyy";
    Console.WriteLine("'{0}' format specifier: {1}",  
                      fmt, thisDate.Date.ToString(fmt));

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version