Get today's date in CSharp

Description

The following code shows how to get today's date.

Example


//w  w w  .  j  av  a  2s  .co  m
using System;

public class Example
{
   public static void Main()
   {
      // Get the current date.
      DateTime thisDay = DateTime.Today;

      Console.WriteLine(thisDay.ToString());
      // Display the date in a variety of formats.
      Console.WriteLine(thisDay.ToString("d"));
      Console.WriteLine(thisDay.ToString("D"));
      Console.WriteLine(thisDay.ToString("g"));
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var