Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement the application of C# date format

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to implement the C# date formatting application". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to implement the C# date formatting application.

What does the C # date formatting application look like? First of all, let's look at a detail, but if you don't know it, it may keep you busy for a long time. Like me today. The discovery of the details stems from the fact that when I modified the algorithm and design analysis teaching website today, I clearly defined that the deadline for submitting homework was 2009-08-20 00:00:00, but it showed at the front desk that it was 2009-08-20 12:00:00. At this point, I fainted. At first I suspected that the server system time had gone wrong again. So it is strange that the remote server finds that the system time is not wrong. Take a look at the storage time of the database table, which is also 00:00:00 on 2009-08-20, so how can it be displayed incorrectly? So look at the code of the page's output time.

EndTime.ToString ("MM-dd hh:mm:ss")

There's nothing wrong with finding out. It was very embarrassing. I was suddenly at a loss.

Resolution of C# date formatting problem:

After thinking about it, I want to manage the background reset time, but the strange thing is that the management background display time is correct. So check the background code, as follows:

Convert.ToDateTime (row ["CoWk_UpoladEndTime"]. ToString ("yyyy-MM-dd (ddd) HH:mm:ss")

Found a difference between HH and hh~~ change the code page of the foreground to HH, and then OK. A detailed knowledge problem ~

Details of C# date formatting:

Format output sample year y7string yy= DateTime.Now.ToString ("y-MM") yy= "7-05" yy07string yy= DateTime.Now.ToString ("yy-MM") yy= "07-05" yyy or more y1984string yy= DateTime.Now.ToString ("yyyy") Yy= "2007" month M5.string mon = DateTime.Parse ("1984-05-09") ToString ("yyyy-M") mon = "1984-5" MM05.string mon = DateTime.Parse ("1984-05-09") ToString ("MM") mon = "05" MMM if it is the Chinese version of the operating system, it will be output: may. If it is an English operating system, enter the abbreviation of the first three letters of the month: Maystring mon = DateTime.Parse ("2006-07-01"). ToString ("MMM") English version operating system: Jul Chinese version operating system: July MMMM or more M if the Chinese version of the operating system, it will be output: may. If it is an English operating system, enter the full write string mon = DateTime.Parse ("2006-07-01") of the month. ToString ("MMM") English version operating system: July Chinese version operating system: July date or week d9string dd= DateTime.Parse ("1984-05-09") ToString ("d") dd= "9" dd09string dd= DateTime.Parse ("1984-05-09") ToString ("dd") dd= "09" ddd if the Chinese version of the operating system, the week will be output Like Wednesday. . If it is an English operating system, the abbreviation of the week will be output: for example, Wedstring dd = DateTime.Parse ("2006-07-01"). ToString ("ddd") English operating system: Wed Chinese operating system: Wednesday dddd or more if the operating system is the Chinese version, the week will be output, such as Wednesday. . If it is an English operating system, output week: such as Wednesdaystring dd = DateTime.Parse ("2006-07-01"). ToString ("dddd") English operating system: Wednesday Chinese operating system: Wednesday hour h range: 1-12string hh = DateTime.Now.ToString ("h"); hh = 8hh or more h hour range: 1-12string hh = DateTime.Now.ToString ("hh") Hh = 08H hour range: 0-23string hh = DateTime.Now.ToString ("yyyy-H"); hh = 2006-8HH or more H-hour range: 0-23string hh = DateTime.Now.ToString ("yyyy-HH"); hh = 2006-08string hh = DateTime.Pare ("2006-7-4 18:00:00"). ToString ("yyyy-HH"); hh = 2006-18 minutes m6string mm = DateTime.Now.ToString ("yyyy-MM-dd-m"); mm = "2006-07-01-6" Mm or more m06string mm = DateTime.Now.ToString ("yyyy-MM-dd-mm"); mm = "2006-07-01-06"; second s6string mm = DateTime.Now.ToString ("yyyy-MM-dd-s"); mm = "2006-07-01-6"; ss or more s06string mm = DateTime.Now.ToString ("yyyy-MM-dd-ss"); mm = "2006-07-01-06"

The description of the above C# date format is:

The DateTime.ToString () function has four overloads. The one that is usually used more often is the one without parameters. Unexpectedly, DateTime.ToString (string format) is more powerful and can output dates in different formats. The following is a list of some situations for your reference. Some are not listed on MSDN.

1.y represents the year, note that it is lowercase y, and uppercase Y does not represent the year.

2. M represents the month.

3.D indicates the date, and note that D does not mean anything.

4. H or H means hours, h uses the 12-hour system, and H uses the 24-hour system.

5.m means minutes.

6.s means seconds. Note that S doesn't mean anything.

At this point, I believe you have a deeper understanding of "how to implement the C# date formatting application". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report