DateTime.ToString(String format, CultureInfo ci) : DateTime « System « C# / C Sharp by API






DateTime.ToString(String format, CultureInfo ci)

 

using System;
using System.Globalization;

public class Example21_10 
{

  public static void Main() 
  {

    // create a date and a currency value
    DateTime dtNow = DateTime.Now;
    Double curOriginal = 12345.67;

    // and format the variables for a specific culture
    CultureInfo ci = new CultureInfo("en-US");
    string sLocalizedDate = dtNow.ToString("d", ci);
    string sLocalizedCur = curOriginal.ToString("c", ci);

    // print them out
    Console.WriteLine(sLocalizedDate);
    Console.WriteLine(sLocalizedCur);

    // and format them for a second culture
    CultureInfo ci2 = new CultureInfo("en-GB");
    string sLocalizedDate2 = dtNow.ToString("d", ci2);
    string sLocalizedCur2 = curOriginal.ToString("c", ci2);

    // print them out again
    Console.WriteLine(sLocalizedDate2);
    Console.WriteLine(sLocalizedCur2);

  }

}

   
  








Related examples in the same category

1.new DateTime
2.new DateTime(0)
3.new DateTime(year, month, day, hour, minute, second, millisecond)
4.DateTime < DateTime
5.DateTime - TimeSpan
6.DateTime.Add(TimeSpan)
7.DateTime.AddSeconds
8.DateTime.AddYears
9.DateTime.Compare(DateTime first, DateTime second)
10.DateTime.Date
11.DateTime.DayOfWeek
12.DateTime.DaysInMonth
13.DateTime.Equals(DateTime dt)
14.DateTime.Equals(DateTime first, DateTime second)
15.DateTime.FromFileTime
16.DateTime.IsDaylightSavingTime()
17.DateTime.IsLeapYear
18.DateTime.Kind
19.DateTime.MaxValue
20.DateTime.Millisecond
21.DateTime.Now
22.DateTime.Parse
23.DateTime.ParseExact
24.DateTime.Second
25.DateTime.Subtract(TimeSpan t)
26.DateTime.Ticks
27.DateTime.TimeOfDay
28.DateTime.Today
29.DateTime.ToFileTime
30.DateTime.ToLongDateString()
31.DateTime.ToLongTimeString()
32.DateTime.ToShortDateString()
33.DateTime.ToShortTimeString()
34.DateTime.ToString(String format)
35.DateTime.UtcNow
36.DateTime.Year