本文整理汇总了C#中System.Globalization.DateTimeFormatInfo.ShortDatePattern属性的典型用法代码示例。如果您正苦于以下问题:C# DateTimeFormatInfo.ShortDatePattern属性的具体用法?C# DateTimeFormatInfo.ShortDatePattern怎么用?C# DateTimeFormatInfo.ShortDatePattern使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Globalization.DateTimeFormatInfo
的用法示例。
在下文中一共展示了DateTimeFormatInfo.ShortDatePattern属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Globalization;
public class SamplesDTFI
{
public static void Main()
{
string[] cultures = { "en-US", "ja-JP", "fr-FR" };
DateTime date1 = new DateTime(2011, 5, 1);
Console.WriteLine(" {0,7} {1,19} {2,10}\n", "CULTURE", "PROPERTY VALUE", "DATE");
foreach (var culture in cultures) {
DateTimeFormatInfo dtfi = CultureInfo.CreateSpecificCulture(culture).DateTimeFormat;
Console.WriteLine(" {0,7} {1,19} {2,10}", culture,
dtfi.ShortDatePattern,
date1.ToString("d", dtfi));
}
}
}
输出:
CULTURE PROPERTY VALUE DATE en-US M/d/yyyy 5/1/2011 ja-JP yyyy/MM/dd 2011/05/01 fr-FR dd/MM/yyyy 01/05/2011
示例2: Main
//引入命名空间
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
DateTimeFormatInfo dtfi = CultureInfo.CreateSpecificCulture("en-US").DateTimeFormat;
DateTime date1 = new DateTime(2011, 5, 1);
Console.WriteLine("Original Short Date Pattern:");
Console.WriteLine(" {0}: {1}", dtfi.ShortDatePattern,
date1.ToString("d", dtfi));
dtfi.DateSeparator = "-";
dtfi.ShortDatePattern = @"yyyy/MM/dd";
Console.WriteLine("Revised Short Date Pattern:");
Console.WriteLine(" {0}: {1}", dtfi.ShortDatePattern,
date1.ToString("d", dtfi));
}
}
输出:
Original Short Date Pattern: M/d/yyyy: 5/1/2011 Revised Short Date Pattern: yyyy/MM/dd: 2011-05-01