DateTime ToString with CultureInfo : Date Time Format « Date Time « C# / C Sharp






DateTime ToString with CultureInfo

       

using System;
using System.Globalization;
using System.Threading;

class Program {
    static void Main(string[] args) {
        DateTime d = new DateTime(2005, 08, 09);
        Console.WriteLine(d.ToLongDateString());
        Console.WriteLine(d.ToString("D", new CultureInfo("fr-FR")));
        CultureInfo ci = Thread.CurrentThread.CurrentCulture;
        Console.WriteLine(ci.ToString() + ": " + d.ToString("D"));

        ci = new CultureInfo("es-ES");
        Thread.CurrentThread.CurrentCulture = ci;
        Console.WriteLine(ci.ToString() + ": " + d.ToString("D"));

    }
}

   
    
    
    
    
    
  








Related examples in the same category

1.use the ToString() method to convert a DateTime to a string
2.use the ToLongTimeString() and ToShortTimeString() methods to convert the time parts of a DateTime to long and short time strings
3.use the FromFileTime() method to convert an operating system file timestamp to a DateTime
4.use the ToFileTime() method to convert a DateTime to an operating system file timestamp
5.Format time and date information 1Format time and date information 1
6.Format time and date information 2Format time and date information 2
7.demonstrates culture formattingdemonstrates culture formatting
8.The next example formats a DateTime with invariant culture. Invariant culture is always the same, regardless of the computer's settings:
9.Request a specific culture (english language in Great Britain):
10.Compare the results of choosing InvariantInfo with those of choosing CurrentInfo:
11.Format date value as short date format
12.Long date format
13.Sortable date format
14.Universal sortable date format
15.Universal full date/time
16.RFC1123 date format
17.Month date format
18.Year date format
19.General date long time format
20.General date/short time format
21.Full date long time format
22.Full date short time format
23.Long time date format
24.Short time date format
25.Contains helper for converting to and from the date formats
26.DateTime Format: %M
27.DateTime format: MMMM dd, yyyy (dddd)
28.DateTime Format: MM-dd-yy
29.DateTime Format: d, M
30.DateTime Format: d MMMM
31.DateTime Format: dd,MM
32.DateTime Format: ddd d MMM
33.DateTime Format: ddd d MMM (fr-FR)
34.DateTime Format: dddd dd MMMM
35.DateTime Format: dddd dd MMMM (it-IT)
36.DateTime Format: : hh:mm:ss.f
37.DateTime Format: hh:mm:ss.F
38.DateTime Format: hh:mm:ss.ff
39.DateTime Format: hh:mm:ss.FF (2)
40.DateTime Format: "hh:mm:ss.fff
41.DateTime Format: hh:mm:ss.FFF
42.DateTime Format: MM/dd/yyyy g
43.DateTime Format: h:m:s.F t
44.DateTime Format: hh:mm:ss.ff tt
45.DateTime Format: H:mm:ss
46.DateTime Format: HH:mm:ss
47.DateTime Format: %K
48.DateTime Format: hh:mm:ss tt
49.DateTime Format: (M) MMM, MMMM
50.DateTime Format: dd, MM
51.DateTime Format: dddd dd MMMM (2)
52.DateTime Format: yyyyy
53.DateTime Format: %z
54.DateTime Format: zzz, zz
55.DateTime Format: %h
56.DateTime Format: h \\h m \\m
57.Format decimal with different cultures
58.Sql format string to Date
59.dateTime.ToString("dd/MM/yyyy ")
60.dateTime.ToString("dd/MM/yyyy hh:mm")
61.DateTime to short and long String
62.Gets the pretty date.
63.Converts a DateTime object into a unix timestamp number.
64.To Unix time
65.Format Time as ##:##:##
66.Format Time as ##/##/## (2)