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 的不支援縮寫的日期名稱,則陣列會包含整日名稱。

適用於

另請參閱