本文整理匯總了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