1. Format date method when binding data control:
2. When using DataBinder.Eval for data binding:
DataBinder.Eval(Container.DataItem,"AddTime","{0:yyyy-MM-dd}")
3. Directly use the ToString method to convert the date display format:
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
4. Use String class to convert date display format:
String.Format("{0:yyyy-MM-dd}", DateTime.Now)
5. Use the DateTime.Parse method to convert the date display format
DateTime.Parse("2012-2-22").ToString("yyyy-MM-dd")
6. Use the Convert.ToDateTime method to convert the date display format:
Convert.ToDateTime("2012-12-21").ToString("yyyy-MM-dd")
Standard DateTime format specifier
http://msdn.microsoft.com/zh-cn/library/az4se3k1(v=vs.80).aspx
Custom DateTime format specifier
http://msdn.microsoft.com/zh-cn/library/8kb3ddd4(v=vs.80).aspx
The above is the detailed content of Several methods of time formatting in Asp.net. For more information, please follow other related articles on the PHP Chinese website!