DateTimeFormatInfo.AbbreviatedDayNames 属性

定义

获取或设置 String 类型的一维数组,它包含周中各天的区域性特定的缩写名称。

public:
 property cli::array <System::String ^> ^ AbbreviatedDayNames { cli::array <System::String ^> ^ get(); void set(cli::array <System::String ^> ^ value); };
public string[] AbbreviatedDayNames { get; set; }
member this.AbbreviatedDayNames : string[] with get, set
Public Property AbbreviatedDayNames As String()

属性值

String[]

一个类型 String 的一维数组,它包含周中各天的特定于区域性的缩写名称。 InvariantInfo 的数组包含"Sun"、"Mon"、"Tue"、"Wed"、"Thu"、"Fri"和"Sat"。

例外

该属性设置为 null

该属性正被设置为多维数组或者长度不是正好为 7 的数组。

设置了该属性,但 DateTimeFormatInfo 对象为只读。

示例

以下示例创建一个读/写CultureInfo对象,该对象代表英语 (美国) 区域性,并将缩写的日期名称分配给其 AbbreviatedDayNames 属性。 然后,它使用 自定义日期和时间格式字符串 中的“ddd”格式说明符显示从 2014 年 5 月 28 日开始的一周内日期的字符串表示形式。

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CultureInfo ci = CultureInfo.CreateSpecificCulture("en-US");
      DateTimeFormatInfo dtfi = ci.DateTimeFormat;
      dtfi.AbbreviatedDayNames = new String[] { "Su", "M", "Tu", "W",
                                                "Th", "F", "Sa" };
      DateTime dat = new DateTime(2014, 5, 28);

      for (int ctr = 0; ctr <= 6; ctr++) {
         String output = String.Format(ci, "{0:ddd MMM dd, yyyy}", dat.AddDays(ctr));
         Console.WriteLine(output);
      }
   }
}
// The example displays the following output:
//       W May 28, 2014
//       Th May 29, 2014
//       F May 30, 2014
//       Sa May 31, 2014
//       Su Jun 01, 2014
//       M Jun 02, 2014
//       Tu Jun 03, 2014
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim ci As CultureInfo = CultureInfo.CreateSpecificCulture("en-US")
      Dim dtfi As DateTimeFormatInfo = ci.DateTimeFormat
      dtfi.AbbreviatedDayNames = { "Su", "M", "Tu", "W", "Th",  
                                   "F", "Sa" }  
      Dim dat As Date = #05/28/2014#

      For ctr As Integer = 0 To 6 
         Dim output As String = String.Format(ci, "{0:ddd MMM dd, yyyy}", dat.AddDays(ctr))
         Console.WriteLine(output)
      Next 
   End Sub 
End Module 
' The example displays the following output:
'       W May 28, 2014
'       Th May 29, 2014
'       F May 30, 2014
'       Sa May 31, 2014
'       Su Jun 01, 2014
'       M Jun 02, 2014
'       Tu Jun 03, 2014

注解

如果设置此属性,则数组必须是一维的,并且必须恰好具有七个元素。 索引为零处 (元素的第一个元素) 表示属性定义的 Calendar 日历中一周的第一天。

如果自定义格式字符串包含“ddd”格式说明符,则 DateTime.ToStringToString 方法包括数组的适当 AbbreviatedDayNames 成员,以取代结果字符串中的“ddd”。

如果属性的值 Calendar 发生更改,则此属性将受到影响。 如果所选 Calendar 的 不支持缩写的日期名称,则数组将包含全天名称。

适用于

另请参阅