Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
A program that returns the current time system
Posted

C#
using System;

class Program
{
    static void Main()
    {
	DateTime time = DateTime.Now;              // Use current time
	string format = "MMM ddd d HH:mm yyyy";    // Use this format
	Console.WriteLine(time.ToString(format));  // Write to console
    }
}
 
Share this answer
 
Comments
VJ Reddy 11-Apr-12 1:38am    
+5 for clear explanation.
uspatel 11-Apr-12 1:41am    
Thanks Reddy.....
The Solution 1 by Uma Shankar Patel is straight to the point. I only want to add that both ddd and d given in the format, print the date and year specified by the formatter yyyy, is generally not printed after the time.
So, one of the standard DateTime formats given here
Standard DateTime Format Strings[^]
or one of the custom DateTime format strings given here
Custom Date and Time Format Strings[^]
will be a better option.
 
Share this answer
 
Comments
uspatel 11-Apr-12 1:43am    
5+Adequate material for DateTime........
VJ Reddy 11-Apr-12 1:55am    
Thank you, Uma Shankar.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900