Date Processing functions in Asp.net
// April 24, 2007
This. textbox6.text = system. datetime. Now. tostring ("D ");
// 2007-4-24
This. textbox7.text = system. datetime. Now. tostring ("D ");
// April 24, 2007 16:30:15
This. textbox8.text = system. datetime. Now. tostring ("F ");
// April 24, 2007
This. textbox9.text = system. datetime. Now. tostring ("F ");
// 2007-4-24 16:30:15
This. textbox10.text = system. datetime. Now. tostring ("G ");
//
This. textbox11.text = system. datetime. Now. tostring ("G ");
// 16:30:15
This. textbox12.text = system. datetime. Now. tostring ("T ");
// 16: 30
This. textbox13.text = system. datetime. Now. tostring ("T ");
// April 24, 2007 8:30:15
This. textbox14.text = system. datetime. Now. tostring ("U ");
// 2007-04-24 16: 30: 15z
This. textbox15.text = system. datetime. Now. tostring ("U ");
// April 24
This. textbox16.text = system. datetime. Now. tostring ("M ");
This. textbox16.text = system. datetime. Now. tostring ("M ");
// Tue, 24 Apr 2007 16:30:15 GMT
This. textbox17.text = system. datetime. Now. tostring ("R ");
This. textbox17.text = system. datetime. Now. tostring ("R ");
// April 2007
This. textbox19.text = system. datetime. Now. tostring ("Y ");
This. textbox19.text = system. datetime. Now. tostring ("Y ");
// 2007-04-24t15: 52: 19.1562500 + 08: 00
This. textboxshorttext = system. datetime. Now. tostring ("O ");
This. textboxshorttext = system. datetime. Now. tostring ("O ");
// 2007-04-24t16: 30: 15
This. textbox18.text = system. datetime. Now. tostring ("S ");
// 2007-04-24 15:52:19
This. textbox21.text = system. datetime. Now. tostring ("yyyy-mm-dd hh: mm: SS: ffff ");
// April 24, 2007 15:56:48
This. textbox22.text = system. datetime. Now. tostring ("mm dd hh, yyyy, MM minutes SS seconds ");
// Tuesday, December April 24, 2007
This. textbox1.text = system. datetime. Now. tostring ("dddd, Mmmm dd YYYY ");
// Second, August 07, April 24
This. textbox2.text = system. datetime. Now. tostring ("DDD, mmm d \" '\ "YY ");
// Tuesday, January 1, April 24
This. textbox3.text = system. datetime. Now. tostring ("dddd, Mmmm dd ");
// 4-07
This. textbox4.text = system. datetime. Now. tostring ("m/YY ");
// 24-04-07
This. textbox5.text = system. datetime. Now. tostring ("DD-mm-yy ");
Label1.text = DT. getdatetimeformats ('s ') [0]. tostring (); // 2005-11-05t14: 06: 25
Label2.text = DT. getdatetimeformats ('T') [0]. tostring (); //
Label3.text = DT. getdatetimeformats ('y') [0]. tostring (); // January 1, November 2005
Label4.text = DT. getdatetimeformats ('D') [0]. tostring (); // November 5, 2005
Label5.text = DT. getdatetimeformats ('D') [1]. tostring (); // 2005 11 05
Label6.text = DT. getdatetimeformats ('D') [2]. tostring (); // Saturday 2005 11 05
Label7.text = DT. getdatetimeformats ('D') [3]. tostring (); // Saturday, January 1, November 5, 2005
Label8.text = DT. getdatetimeformats ('M') [0]. tostring (); // January 1, November 5
Label9.text = DT. getdatetimeformats ('F') [0]. tostring (); // November 5, 2005
Label10.text = DT. getdatetimeformats ('G') [0]. tostring (); //
Label11.text = DT. getdatetimeformats ('R') [0]. tostring (); // sat, 05 Nov 2005 14:06:25 GMT
Convert string to string
12345. tostring ("N"); // generate 12,345.00
12345. tostring ("C"); // generate $12,345.00
12345. tostring ("e"); // generate 1.234500e + 004
12345. tostring ("F4"); // generate 12345.0000
12345. tostring ("X"); // generate 3039 (hexadecimal)
12345. tostring ("p"); // generate 1,234,500
The standard numeric string is defined as follows:
Format description
C or C
Currency
Convert a number to a string that represents the monetary amount. Conversion is controlled by the currency format information of the numberformatinfo object used to format numbers. The precision specifier indicates the number of decimal places required. If the precision specifier is omitted, the default currency precision given by numberformatinfo is used.
D Or d
Decimal number
Only integer types support this format. Convert a number to a string of a decimal number (0-9). If the number is negative, a negative sign is added. The precision specifier indicates the minimum number of digits required in the result string. If necessary, fill the left side of the number with zero to generate the number specified by the precision specifier.
E or E
Scientific notation (INDEX)
Convert the number to "-D. DDD... E + DDD "or"-D. DDD... E + DDD string, where each "D" represents a number (0-9 ). If this number is negative, the string starts with a minus sign. There is always a number before the decimal point. The precision specifier indicates the number of digits required after the decimal point. If the precision specifier is omitted, the default value is used, that is, six digits after the decimal point. The case description indicates whether to add the prefix "E" or "e" before the index ". An index is always composed of a positive or negative number and at least three digits. If needed, fill the index with zero to meet the requirements of at least three digits.
F or F
Fixed Point
Convert numbers to "-DDD. DDD ..." String, where each "D" represents a number (0-9 ). If this number is negative, the string starts with a minus sign. The precision specifier indicates the number of decimal places required. If the precision specifier is ignored, the default numeric precision given by numberformatinfo is used.
G or G
General
Based on the number type and whether there is a precision specifier, the number is converted to the most compact form of a fixed point or scientific notation. If the precision specifier is omitted or zero, the default precision is determined by the number type, as shown in the following table.
Byte or sbyte: 3
Int16 or uint16: 5
Int32 or uint32: 10
Int64 or uint64: 19
Single: 7
Double: 15
Decimal: 29
If the index is greater than-5 and less than the precision specifier when the number is expressed in scientific notation, the fixed point notation is used; otherwise, the scientific notation is used. If a decimal point is required and Zero tail is ignored, the result contains the decimal point. If the precision specifier exists and the number of valid digits in the result exceeds the specified precision, the redundant trailing digits are deleted by rounding. When scientific notation is used, if the format specifier is "g", the result index carries the prefix "e"; if the format specifier is "g ", the index of the result is prefixed with "E ".
The preceding rule has one exception: if the number is decimal and the precision specifier is omitted. In this case, the fixed point notation is always used and the tail zero is retained.
N or N
Number
Convert numbers to "-D, DDD, DDD ..." String, where each "D" represents a number (0-9 ). If this number is negative, the string starts with a minus sign. A thousands separator is inserted between every three digits on the left of the decimal point. The precision specifier indicates the number of decimal places required. If the precision specifier is ignored, the default numeric precision given by numberformatinfo is used.
P or P
Percentage
The number is converted to a percent string defined by the numberformatinfo. percentnegativepattern attribute or the numberformatinfo. percentpositivepattern attribute. If the number is negative, the generated string is defined by percentnegativepattern and starts with a negative number. The converted number is multiplied by 100 as a percentage. The precision specifier indicates the number of decimal places required. If the precision specifier is omitted, the default numeric precision given by numberformatinfo is used.
R or R
Round-trip Process
The description of the round-trip process ensures that the value converted to a string is analyzed as the same value again. When formatting a value using this specifier, first test it using the regular format: Double uses 15-bit precision, and single uses 7-bit precision. If the value is successfully analyzed back to the same value, it is formatted using the regular format specifier. However, if the value is not successfully analyzed as the same value, it is formatted as follows: Double uses 17-bit precision, and single uses 9-bit precision. Although the precision specifier can be appended to the format specifier of the round-trip process, it will be ignored. When this specifier is used, the round-trip process takes precedence over precision. This format is only supported by the floating point type.
X or X
Hexadecimal number
A string that converts a number to a hexadecimal number. The case description indicates whether to use uppercase or lowercase letters for hexadecimal numbers greater than 9. For example, "X" is used to generate "abcdef" and "X" is used to generate "abcdef ". The precision specifier indicates the minimum number of digits required in the result string. If necessary, fill the left side of the number with zero to generate the number specified by the precision specifier. Only integer types support this format.
Search "string of standard numeric format" in msdn to obtain
3. Use the system. Math. Round Function to specify the number of decimal places.
Source: http://www.cnblogs.com/lingyuan/archive/2010/10/26/1861510.html