net 4 and C #.
I have a DateTimeValue text box
3/1/2011 12:00:00 AM
I need to convert it to a string of this format:
Format="yyyy-MM-dd"
Any idea how to do this? PS: I can delete time information
thank you for your time
Use DateTime.ParseExact like this:
DateTime.ParseExact("3/1/2011 12:00:00 AM", "G", CultureInfo.GetCultureInfo("en-US")).ToString("yyyy-MM-dd");
Be sure to indicate the culture, because the format you use is ambiguous.
Is this what you are asking for?
DateTime.Parse("3/1/2011 12:00:00 AM").ToString("yyyy-MM-dd")
: System.Globalization, CultureInfo.
: using System.Globalization; // for CultureInfo
using System.Globalization; // for CultureInfo
Convert.ToDateTime(Text1.Text).ToString( "--" )
. . , , . () DateTime.Parse.
: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
, :
DateTime date = new DateTime(2011, 3, 1); date.ToString("yyyy-MM-dd")
string dt = DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString();