w3resource logo


C# Sharp Programming Exercises

C# Sharp Exercises: Demonstrate the Day property

Secondary Nav

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.)

Expected Output :

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

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);
    
   }
}

C# Sharp Practice online:

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);
    
   }
}

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program