Converting the datetime format
Using C# & asp.net
Textbox values are = "04/03/2010"
Format: mm/dd/yyyy
I want to convert the date like this 2010-03-04 instead of 04/03/2010
F开发者_如何学运维ormat: yyyy-mm-dd
how to make a code for converting this values....
string newValue = DateTime.ParseExact(oldValue, "MM'/'dd'/'yyyy", null)
.ToString("yyyy'-'MM'-'dd");
The documentation: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
date.ToString("yyyy-MM-dd");
Convert the input value to a date using Date.ParseExact which takes the format as second argument. You'll specify MM/dd/yyyy for that. Then convert the resulting date to your format using ToString("yyyy-MM-dd")
string x = "04/03/2010"
date dte = date.parse(x)
textbox.text = string.format("{0}-{1}-{2}", dte.year,dte.month,dte.day)
精彩评论