From: http://www.cnblogs.com/enuosky/archive/2006/08/29/489014.html
Dataformatstring = "{0: Format String }"
{0} In dataformatstring represents the data itself, while the format string after the colon represents the format they want to display the data;
Number and currency format:After the specified format symbol, you can specify the number of digits to be displayed in decimal places. For example, if the original data is "1.56" and the format is set to {0: N1}, the output is "1.5 」. The
String in dataformatstring formatDataformatstring = "{0: Format String }"
{0} In dataformatstring represents the data itself, while the format string after the colon represents the format they want to display the data;
Number and currency format:After the specified format symbol, you can specify the number of digits to be displayed in decimal places. For example, if the original data is "1.56" and the format is set to {0: N1}, the output is "1.5 」. The common numeric format is shown in the f
Total: {0:c} ' 12345.6789 total: $12345.68
Its commonly used date formats are shown in the following table:
Format Description Output format
D Compact Date format mm/dd/yyyy
D Detail Date format dddd, MMMM DD, yyyy
F Full Format (long date + short time) dddd, MMMM dd,
number format. Z Displays the time zone offset without leading zeros (for example,-8). If this is the only character in a user-defined number format, use%z. ZZ Displays a time zone offset with a leading zero (for example, -08) ZZZ displays the full time zone offset (for example, -08:00) in the format display m/d/yy12/7/58d-mmm7-decd-mmmm-yy7-december-58d MMMM7 Decembermmmm yydecember 58hh:mm tt08:50 PMh:mm:ss t8:50:35 ph:mm20:50h:mm:ss20:50:35m/d/
M
5.
String mon = DateTime.Parse ("1984-05-09")ToString("Yyyy-m")Mon = "1984-5"
Mm
05.
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 first three letters of the month: May
S
"
Month
M
5.
String mon = DateTime.Parse ("1984-05-09") ToString ("Yyyy-m")Mon = "1984-5"
Mm
05.
String mon = DateTime.Parse ("1984-05-09") ToString ("M M")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 first thre
(3) Double i=12345.6789;
This.textbox1.text=i.tostring ("F2"); Result 12345.68
This.textbox2.text=i.tostring ("F6");
Result 12345.678900
(4) Double i=12345.6789;
This.textbox1.text=i.tostring ("n"); Results 12,345.68
This.textbox2.text=i.tostring ("N4"); Results 12,345.6789
(5) Double i=0.126;
String s=string. Format ("The value is {0:p}", i);
This.textbox1.text=i.tostring ("P"); Result 12.6%
This.textbox2.text=s; Results The value is 12.6%
(6) DateTime dt =new datetime (2003,5,25);
This.textbo
doesn't mean anything.
Format
Output
Example
Years
Y
7
String yy = DateTime.Now. ToString ("y-mm")Yy= "7-05"
Yy
07
String yy = DateTime.Now. ToString ("yy-mm")Yy= "07-05"
yyy or more Y
1984
String yy = DateTime.Now. ToString ("yyyy");Yy= "2007"
leading zero.Abbreviated name of the MMM month, defined in AbbreviatedMonthNames.The full name of the MMMM month, as defined in MonthNames.Y does not contain the year of the era. If the year that does not contain an era is less than 10, the year is displayed without leading zeros.YY does not contain the year of the era. If the year that does not contain an era is less than 10, the year with leading zeros is displayed.The
specified format symbol, you can specify the number of digits to display for the decimal. For example, the original data is "1.56", and if the format is set to {0:n1}, the output is "1.5". Its commonly used numeric format is shown in the following table:
format string input result
"{0:c}" 12345.6789 $12,345.68 "{0:c}" -12345.6789 ($12,345.68) "{0:d}" 12345 12345 "{0:d8}" 12345 00012345 "{0:e}" 12345.6789 1234568E+004 "{0:e10}" 12345.6789 1.2345678900E+004 "{0:f}" 12345.6789 12345.68 "{0:f0}" 12
. Getdatetimeformats (' g ') [0].ToString ()); 26/11/2009 PM 1:29Console.WriteLine (dt. Getdatetimeformats (' R ') [0].ToString ()); Thu, 13:29:06 GMTNoteCommon Date-time formats:Format Description Output formatD Thin Date format mm/dd/yyyyD Detailed date format dddd, MMMM DD, yyyyF Full Format (long date + short time) dddd, MMMM dd, yyyy hh:mmF full DateTime for
decimal will display after the specified format symbol. For example, the original data is "12.34", and if the format is set to {0:n1}, the output is "12.3". Its commonly used numeric format is shown in the following table:
format string Data results
"{0:c}" 12345.6789 $12,345.68
"{0:c}"-12345.6789 ($12,345.68)
"{0:d}" 12345 12345
"{0:d8}" 12345 00012345
"{0:e}" 12345.6789 1234568E+004
"{0:e10}" 12345.6789 1.2345678900E+004
"{0:f}" 12345.6789 12345.68
"{0:f0}" 12345.6789 12346
Dataformatstring = "{0: Format String }"
{0} In dataformatstring represents the data itself, while the format string after the colon represents the format they want to display the data;
Number and currency format:After the specified format symbol, you can specify the number of digits to be displayed in decimal places. For example, if the original data is "1.56" and the format is set to {0: N1}, the output is "1.5 」. The common numeric format is shown in the following table:
Format String
Dataformatstring = "{0: Format String }"
We know that {0} In dataformatstring represents the data itself, while the format string after the colon represents the format that we want the data to display; in addition, after the specified format symbol, you can specify the number of digits to be displayed in decimal places. For example, if the original data is "12.34" and the format is set to {0: N1}, the output is "12.3 」. The common numeric format is shown in the following table:
Format Stri
completely in accordance with the custom format to output!C. DateTime dt = new datetime (yyyy, M, D, H,m, s);//yyyy-mm-dd HH:mm:ssString.Format ("{0:y yy yyy yyyy}", DT); "8 008" yearString.Format ("{0:m MM MMM MMMM}", DT); "3 Mar March" monthString.Format ("{0:d dd ddd dddd}", DT); "9 Sun Sunday" DayString.Format ("{
are displayed for regional settings that use a 24-hour system.
y
Displays the year (0-9) as a number with no leading zeros. If this is the only character in the user-defined number format, use %y.
yy
Displays the year in two-digit format with a leading zero, if applicable.
yyy
Displays the year in four-bit number format.
yyyy
"{0: N4}" 123456789 123,456,789.0000"Total: {0: C}" 12345.6789 Total: $12345.68
The commonly used date formats are shown in the following table:
Format description output formatD. Simplified Date Format: MM/dd/yyyyD detailed Date Format: dddd, MMMM dd, yyyyF full format (long date + short time) dddd, MMMM dd, yyyy HH: mmF complete date and time Format (long date
object to a string based on the local time format.7) tolocaletimestring () converts the time portion of a Date object to a string, based on the local time format.8) tolocaledatestring () converts the date part of a dates object to a string, based on the local time format.Although the JavaScript Date object has built-in methods to provide these output as strings, these strings are not in our control format, so what if we need our own custom special format?Moment provides a powerful format functi
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.