本文整理匯總了C#中System.Globalization.DateTimeFormatInfo.DateSeparator屬性的典型用法代碼示例。如果您正苦於以下問題:C# DateTimeFormatInfo.DateSeparator屬性的具體用法?C# DateTimeFormatInfo.DateSeparator怎麽用?C# DateTimeFormatInfo.DateSeparator使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Globalization.DateTimeFormatInfo
的用法示例。
在下文中一共展示了DateTimeFormatInfo.DateSeparator屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
DateTime value = new DateTime(2013, 9, 8);
string[] formats = { "d", "G", "g" };
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
DateTimeFormatInfo dtfi = culture.DateTimeFormat;
dtfi.DateSeparator = "-";
foreach (var fmt in formats)
Console.WriteLine("{0}: {1}", fmt, value.ToString(fmt, dtfi));
}
}
輸出:
d: 9-8-2013 G: 9-8-2013 12:00:00 AM g: 9-8-2013 12:00 AM
示例2: Main
//引入命名空間
using System;
using System.Globalization;
using System.Threading;
class Class1 {
static void Main(string[] args) {
CultureInfo MyCulture = new CultureInfo("fr-FR");
DateTime MyDate = System.DateTime.Now;
Thread.CurrentThread.CurrentCulture = MyCulture;
DateTimeFormatInfo dtf = MyCulture.DateTimeFormat;
//Change date and time separator
dtf.DateSeparator = "\\";
dtf.TimeSeparator = "&";
Console.WriteLine();
Console.WriteLine(MyDate.ToLongDateString());
Console.WriteLine(MyDate.ToLongTimeString());
Console.WriteLine(MyDate.ToShortDateString());
Console.WriteLine(MyDate.ToShortTimeString());
}
}