34,333
edits
Changes
→Getting the Current System Time and Date
== Getting the Current System Time and Date ==
The system date and time of the computer on which the C# code is executing may be accessed using the ''Today'' and ''Now'' static properties of the DateTime class. The ''Today'' property will return the current system date (and also the time set to 12:00 AM) whilst the ''Now'' property returns the current date and time.
For example:
<pre>
using System;
class TimeDemo
{
static void Main()
{
System.Console.WriteLine (DateTime.Today.ToString()
System.Console.WriteLine (DateTime.Now.ToString());
}
}
</pre>
== Formating Dates and Times in C# ==
There are number of techniques available for extracting and displaying dates and times in particular formats. Output may be configured using a small number of predifined formatting methods or customized with an almost infinite number of variations using the ToString() method.
The basic formatting methods operate as follows:
<pre>
== Adding or Subtracting from Dates and Times ==