w3resource
C# Sharp Programming Exercises

C# Sharp Exercises: Demonstrate the Day property

C# Sharp DateTime: Exercise-2 with Solution

Write a C# Sharp program to display the Day properties (year, month, day, hour, minute, second, millisecond etc.)

Sample Solution:-

C# Sharp Code:

using System;

public class Example2
{
   public static void Main()
   {
    System.DateTime moment = new System.DateTime(2016, 8, 16, 3, 57, 32, 11);

	Console.WriteLine("year = " +moment.Year);

	Console.WriteLine("month = " +moment.Month);

	Console.WriteLine("day = " +moment.Day);

	Console.WriteLine("hour = " +moment.Hour);

	Console.WriteLine("minute = " +moment.Minute);

	Console.WriteLine("second = " +moment.Second);

	Console.WriteLine("millisecond = " +moment.Millisecond);
    
   }
}

Sample Output:

year = 2016                                                                                                  
month = 8                                                                                                  
day = 16                                                                                                  
hour = 3                                                                                                  
minute = 57                                                                                                  
second = 32                                                                                                  
millisecond = 11 

Flowchart :

Flowchart: C# Sharp Exercises - Demonstrate the Day property

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp program to extract the Date property and display the DateTime value in the formatted output.
Next: Write a C# Sharp program to get the day of the week for a specified date.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming