Monday, 2 September 2013

STRING FORMATS FOR DATE TIME ,DECIMALS AND TIME ZONE IN C#?

1)  string str="\"" + "Raj" + "\"";-----to add double quotes in the string  
2)  String.Format("{0:0.00}", 3.8456))
 
just two decimal places
3)  String.Format("{0:0.00}", 123.4567);      // "123.46"
4)  String.Format("{0:0.00}", 123.4);         // "123.40"
5)  String.Format("{0:0.00}", 123.0);         // "123.00"
 
// max. two decimal places
 
6)  String.Format("{0:0.##}", 123.4567);      // "123.46"
7)  String.Format("{0:0.##}", 123.4);         // "123.4"
8)  String.Format("{0:0.##}", 123.0);         // "123"
 
at least two digits before decimal point
9)  String.Format("{0:00.0}", 123.4567);      // "123.5"
10)   String.Format("{0:00.0}", 23.4567);       // "23.5"
11)   String.Format("{0:00.0}", 3.4567);        // "03.5"
12)   String.Format("{0:00.0}", -3.4567);       // "-03.5"
Thousand Seperator
13)   String.Format("{0:0,0.0}", 12345.67);     // "12,345.7"
14)   String.Format("{0:0,0}", 12345.67);       // "12,346"
15)    
16)   String.Format("{0:0.0}", 0.0);            // "0.0"
17)   String.Format("{0:0.#}", 0.0);            // "0"
18)   String.Format("{0:#.0}", 0.0);            // ".0"
19)   String.Format("{0:#.#}", 0.0);            // ""
20)   String.Format("{0:0.00;minus 0.00;zero}", 123.4567);   // "123.46"
21)   String.Format("{0:0.00;minus 0.00;zero}", -123.4567);  // "minus 123.46"
22)   String.Format("{0:0.00;minus 0.00;zero}", 0.0);        // "zero"
23)    
24)   String.Format("{0:my number is 0.0}", 12.3);   // "my number is 12.3"
25)   String.Format("{0:0aaa.bbb0}", 12.3);          // "12aaa.bbb3"
  
/ create date time 2008-03-09 16:05:07.123
26)   DateTimedt = newDateTime(2008, 3, 9, 16, 5, 7, 123);
27)   String.Format("{0:y yyyyyyyyy}", dt);  // "8 08 008 2008"   year
28)   String.Format("{0:M MM MMM MMMM}", dt);  // "3 03 Mar March"  month
29)   String.Format("{0:d ddddddddd}", dt);  // "9 09 Sun Sunday" day
30)   String.Format("{0:h hh H HH}",     dt);  // "4 04 16 16"      hour 12/24
31)   String.Format("{0:m mm}",          dt);  // "5 05"            minute
32)   String.Format("{0:s ss}",          dt);  // "7 07"            second
33)   String.Format("{0:f fffffffff}", dt);  // "1 12 123 1230"   sec.fraction
34)   String.Format("{0:F FF FFF FFFF}", dt);  // "1 12 123 123"    without zeroes
35)   String.Format("{0:t tt}",          dt);  // "P PM"            A.M. or P.M.

36)   String.Format("{0:z zzzzz}",      dt);  // "-6 -06 -06:00"   time zone

No comments:

Post a Comment