Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi Guys I tried that requirement I got the error as "Input string was not in a correct format".

I want the date format like this "Thursday, August 30, 2007 11:19:59 AM". how can do this in windows form.

I was tried as

C#
private void Form1_Load(object sender, EventArgs e)
        {
            label1.Text =  string.Format("{r}", System.DateTime.Now);
        }




Here r is specifier.
Posted
Updated 9-Oct-12 19:18pm
v3

hi, try this:
C#
private void Form1_Load(object sender, EventArgs e)
        {
            label1.Text =  System.DateTime.Now.ToString("F");
        }
 
Share this answer
 
Comments
CH Guravaiah 10-Oct-12 1:31am    
thank you
tanweer 10-Oct-12 1:45am    
mark as answer if it solves your problem
Andy411 10-Oct-12 1:53am    
Thx, you have brought me the ToString(string format) method back in mind :-)
tanweer 10-Oct-12 1:58am    
:p
Hi,

take a look at DateTime.ToLongDateString() and ToLongTimeStamp()

C#
DateTime d = DateTime.Now;
string s = d.ToLongDateString() + " " + d.ToLongTimeString();

In en-US it will result in
Wednesday, October 10, 2012 7:44:40 AM


and in de-DE it will result in
Mittwoch, 10. Oktober 2012 07:46:56


If you're using these methods, the time format will allways be correct regarding the current culture.
 
Share this answer
 
v2
Try :
C#
label1.Text = DateTime.Now.ToString("dddd, MMMM dd, yyyy hh:MM:ss");
 
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