This is a C# Program to display date in string.
Problem Description
This C# Program Displays Date in String.
Problem Solution
Here the date is displayed and month, day and year are separately displayed.
Program/Source Code
Here is source code of the C# Program to Display Date in String. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Display Date in String */ using System; namespace DateAndTime { class Program { static int Main() { DateTime date = new DateTime(2013,6, 23); string strDate = date.ToString("M"); Console.WriteLine("Date and Time : {0}", date); Console.WriteLine("Month and Date : {0}", strDate); Console.Read(); return 0; } } }
Program Explanation
This C# program is used to display date in string. The DateTime() function is used to display the date and month, day and year are printed separately.
advertisement
advertisement
Runtime Test Cases
Date and Time : 6/23/2013 12:00:00 AM Month and Date : June 23
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
If you wish to look at all C# Programming examples, go to 1000 C# Programs.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Apply for Computer Science Internship
- Check MCA Books
- Check C# Books
- Practice MCA MCQs
- Practice Computer Science MCQs