本文整理匯總了C#中System.Globalization.DateTimeFormatInfo.TimeSeparator屬性的典型用法代碼示例。如果您正苦於以下問題:C# DateTimeFormatInfo.TimeSeparator屬性的具體用法?C# DateTimeFormatInfo.TimeSeparator怎麽用?C# DateTimeFormatInfo.TimeSeparator使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Globalization.DateTimeFormatInfo
的用法示例。
在下文中一共展示了DateTimeFormatInfo.TimeSeparator屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
DateTime value = new DateTime(2013, 9, 8, 14, 30, 0);
string[] formats = { "t", "T", "f", "F", "G", "g" };
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
DateTimeFormatInfo dtfi = culture.DateTimeFormat;
dtfi.TimeSeparator = ".";
foreach (var fmt in formats)
Console.WriteLine("{0}: {1}", fmt, value.ToString(fmt, dtfi));
}
}
輸出:
t: 2.30 PM T: 2.30.00 PM f: Sunday, September 08, 2013 2.30 PM F: Sunday, September 08, 2013 2.30.00 PM G: 9/8/2013 2.30.00 PM g: 9/8/2013 2.30 PM
示例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());
}
}