Click here to Skip to main content
15,909,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a string and I want to format is the same as follow:"yyyy/mm/dd hh:mm"
and then set not to a label.text=....
Can you help me?
thanks you.
Posted
Comments
Prerak Patel 24-Feb-11 6:51am    
Convert your string to date and then format that date to your format.
Pravin Patil, Mumbai 24-Feb-11 7:49am    
I think this is the correct solution..
ngthtra 24-Feb-11 23:22pm    
Thanks I resolved my problem.
DateTime sss =convert.toDatetime(str); lable.tex=string.Format("{0:yyy/mm/dd hh:mm}",sss);

 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Feb-11 15:48pm    
Sure, enough said, my 5
--SA
every time i said that please first google your question
i google your question and found just in 0.02sec :)
why you don't try to search by yourself :confused:

below code will help you!

// create date time 2008-03-09 16:05:07.123
DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);

String.Format("{0:y yy yyy yyyy}", dt);  // "8 08 008 2008"   year
String.Format("{0:M MM MMM MMMM}", dt);  // "3 03 Mar March"  month
String.Format("{0:d dd ddd dddd}", dt);  // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}",     dt);  // "4 04 16 16"      hour 12/24
String.Format("{0:m mm}",          dt);  // "5 05"            minute
String.Format("{0:s ss}",          dt);  // "7 07"            second
String.Format("{0:f ff fff ffff}", dt);  // "1 12 123 1230"   sec.fraction
String.Format("{0:F FF FFF FFFF}", dt);  // "1 12 123 123"    without zeroes
String.Format("{0:t tt}",          dt);  // "P PM"            A.M. or P.M.
String.Format("{0:z zz zzz}",      dt);  // "-6 -06 -06:00"   time zone



source link
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 24-Feb-11 15:48pm    
Obaid, I voted "5" only to compensate voted of three idiots who only demonstrated their support of extreme laziness and ignorance. Don't afraid to tell the lazy that they are lazy! After all, they are trying to be lazy not only at your expense but also at expense of other good helping people. Also, this is for their own good, first of all.
--SA
Obaid Ahmed 24-Feb-11 23:06pm    
thanks man :)
why dont you use this:
string dt;
DateTime date = DateTime.Now;    // display format: 4/25/2008 11:45:44 AM
dt = date.ToLongDateString();          // display format:  Friday, April 25, 2008 
dt = date.ToShortDateString();         // display format:  4/25/2008
dt = date.ToShortTimeString();        // display format: 11:45 AM
dt = date.ToLongTimeString();        // display format:  11:45:44 AM

or this is what you want:
Console.WriteLine("s = {0:s}", CurrTime );  // yyyy-mm-dd hh:mm:ss  can be sorted!
 
Share this answer
 
v2
I see your ways is not correct to my request(yyyy/mm/dd hh:mm). But I think Prerak Patel's answer can help me but it is not code so I will try. If you have any code that it can resolve my problem, upload it please.
thanks.
 
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