本文整理汇总了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());
}
}