1. Data Control Binding Format Date method:
The code is as follows:
<asp:boundcolumn datafield= " addtime Headertext= Dataformatstring=" {0 : Yyyy-mm-dd hh:mm}></asp:boundcolumn> <asp:boundfield datafield= addtime Headertext= Dataformatstring=" {0 : yyyy-mm-dd} />
2. Use DataBinder.Eval for data binding:
The code is as follows:
DataBinder.Eval (Container.DataItem,"addtime","{0:yyyy-mm-dd}" )
3. Convert the date display format directly with the ToString method:
The code is as follows:
DateTime.Now.ToString ("yyyy-mm-dd HH:mm:ss")
4. Use the string class to convert the date display format:
The code is as follows:
String.Format ("{0:yyyy-mm-dd}", DateTime.Now)
5. Convert the date display format using the DateTime.Parse method
The code is as follows:
DateTime.Parse ("2012-2-22"). ToString ("yyyy-mm-dd")
6. Convert the date display format using the Convert.todatetime method:
The code is as follows:
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