DateTime properties

In this chapter you will learn:

  1. Display the Date, Day, DayOfWeek, DayOfYear, Ticks, and TimeOfDayProperties of DateTime

DateTime parts

using System;//from java  2  s .  co m

class MainClass
{

  public static void Main()
  {
    
    DateTime myDateTime = DateTime.Now;

    Console.WriteLine("myDateTime.Date = " + myDateTime.Date);
    Console.WriteLine("myDateTime.Day = " + myDateTime.Day);
    Console.WriteLine("myDateTime.DayOfWeek = " + myDateTime.DayOfWeek);
    Console.WriteLine("myDateTime.DayOfYear = " + myDateTime.DayOfYear);
    Console.WriteLine("myDateTime.Ticks = " + myDateTime.Ticks);
    Console.WriteLine("myDateTime.TimeOfDay = " + myDateTime.TimeOfDay);



  }

}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Create a TimeSpan that represents a specified number of days
  2. Create a TimeSpan that represents a specified number of hours
  3. Returns a TimeSpan that represents a specified number of milliseconds
  4. Returns a TimeSpan that represents a specified number of minutes
Home » C# Tutorial » Date, Time, TimeZone
Compare DateTimeOffset
DateTimeOffset creation
Date time Value from DateTimeOffset
Compare DateTime value
DateTime constant value
DateTime constructor
DateTime properties
Create TimeSpan From
TimeSpan
TimeSpan add and subtract
DateTime and TimeSpan
Compare TimeSpan
TimeSpan constant
TimeSpan Constructor
TimeSpan Duration
TimeSpan format
Negate a TimeSpan
TimeSpan operators
Parse string to TimeSpan
TimeSpan to string
TimeSpan total properties
TimeSpan propeties
Daylight saving
Time zone ID
UTC offset with TimeZone
TimeZone converting
TimeZone creation