Home > Backend Development > C#.Net Tutorial > Several methods of time formatting in Asp.net

Several methods of time formatting in Asp.net

巴扎黑
Release: 2017-04-30 10:24:09
Original
1656 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template