In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the C# date data". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. let's follow the editor's train of thought to study and learn what the C# date data is.
C# date data
In the process of programming, it is usually necessary to output C# date data in a certain format, of course, the output must be a string. To do this, we need to use the ToString () method of the System.DateTime class and specify a format string for it.
In MSDN, there is a very detailed description of the pattern string in the overview of the System.Globalization.DateTimeFormatInfo class, so here I will only explain some of the commonly used formats, first of all, take a look at the following table:
There is no leading zero for a single-digit date on a certain day in the d-month.
A single-digit date on a certain day of the dd month has a leading zero
The abbreviated name of the day of the week in ddd is defined in AbbreviatedDayNames
The full name of the day of the week in dddd is defined in DayNames
M-month number single-digit month has no leading zero
MM month numbers single-digit months have a leading zero
The abbreviated name of MMM month is defined in AbbreviatedMonthNames
The full name of the MMMM month is defined in MonthNames
Y A year that does not contain an era if the year that does not contain an era is less than 10, then the year without a leading zero is displayed
Yy year that does not contain an era if the year that does not include an era is less than 10, the year with a leading zero is displayed
Yyyy includes the four-digit year of the era
H 12-hour single-digit hours without leading zeros
Hh 12-hour hourly single-digit hours have a leading zero
H 24-hour single-digit hours have no leading zero
HH 24-hour system has a leading zero for single-digit hours.
M-minute single-digit minutes without leading zeros
The number of single-digit minutes in mm minutes has a leading zero
S seconds single digit seconds without leading zeros
The number of single-digit seconds in ss seconds has a leading zero
To make it easier for you to understand, try the following procedure:
Private void TestDateTimeToString () {DateTime now = DateTime.Now; string format; this.textBox1.Text = ""; format = "yyyy-MM-dd HH:mm:ss"; this.textBox1.AppendText (format + ":" + now.ToString (format) + "\ n"); format = "y M day d"; this.textBox1.AppendText (format + ":" + now.ToString (format) + "\ n");}
This program will output the result: yyyy-MM-dd HH:mm:ss: 2002-08-26 17:03:04 yy M day d: 02 8 26, at this time, there is another problem, what if the text information to be output contains format characters? Such as
Format = "year: yyyy, month: MM, day: dd"; this.textBox1.AppendText (now.ToString (format) + "\ n")
Output: 2ear: 2002, 4on 5: 08, 26a2: 26, this is not the result I want, what should I do? There's a way.
Format = "\" year\ ": yyyy,\ 'month\': MM,\ 'day\': dd"; this.textBox1.AppendText (now.ToString (format) + "\ n")
Look, the result of this run is right: year: 2002, month: 08, day: 26
Thank you for your reading, the above is the content of "what is the C# date data". After the study of this article, I believe you have a deeper understanding of what the C# date data is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.