Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
 ShortDatePattern Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2010/.NET Framework 4

Other versions are also available for the following:
.NET Framework Class Library
DateTimeFormatInfo..::.ShortDatePattern Property

Updated: December 2010

Gets or sets the format pattern for a short date value, which is associated with the "d" format pattern.

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)
Visual Basic
Public Property ShortDatePattern As String
C#
public string ShortDatePattern { get; set; }
Visual C++
public:
property String^ ShortDatePattern {
    String^ get ();
    void set (String^ value);
}
F#
member ShortDatePattern : string with get, set

Property Value

Type: System..::.String
The format pattern for a short date value, which is associated with the "d" format pattern.
ExceptionCondition
ArgumentNullException

The property is being set to nullNothingnullptra null reference (Nothing in Visual Basic).

InvalidOperationException

The property is being set and the DateTimeFormatInfo object is read-only.

See Custom Date and Time Format Strings for patterns that can be combined to construct custom patterns, for example, "MM/dd/yyyy".

This property is affected if the value of the Calendar property changes.

The DateSeparator property is derived from the ShortDatePattern property. Your applications are recommended to set the short date pattern to the exact value of interest, instead of attempting to have the date separator replaced. For example, to obtain the pattern MM-DD-yyyy, the application should set "MM-DD-yyyy" specifically. This also permits the setting of patterns such as "MM/DD, yyyy" that don't contain a traditional separator between all parts of the format.

The following example displays the value of the ShortDatePattern property and the value of a date formatted using the ShortDatePattern property for a few cultures.

Visual Basic
Imports System.Globalization

Public Class SamplesDTFI
   Public Shared Sub Main()
      Dim cultures() As String = { "en-US", "ja-JP", "fr-FR" }
      Dim date1 As Date = #05/01/2011#

      Console.WriteLine(" {0,7} {1,19} {2,10}", "CULTURE", "PROPERTY VALUE", "DATE")
      Console.WriteLine()

      For Each culture As String In cultures
         Dim dtfi As DateTimeFormatInfo = CultureInfo.CreateSpecificCulture(culture).DateTimeFormat
         Console.WriteLine(" {0,7} {1,19} {2,10}", culture, 
                           dtfi.ShortDatePattern, 
                           date1.ToString("d", dtfi))
      Next                     
   End Sub 
End Class
' The example displays the following output:
'        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
C#
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));
      }
   }
}
// The example displays the following output:
//        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

The following example modifies the ShortDatePattern property of a DateTimeFormatInfo object that represents the formatting conventions of the English (United States) culture. It also displays a date value twice, first to reflect the original ShortDatePattern property and then to reflect the new property value.

Visual Basic
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim dtfi As DateTimeFormatInfo = CultureInfo.CreateSpecificCulture("en-US").DateTimeFormat
      Dim date1 As DateTime = #05/01/2011#
      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))
   End Sub
End Module
' The example displays the following output:
'    Original Short Date Pattern:
'       M/d/yyyy: 5/1/2011
'    Revised Short Date Pattern:
'       YYYY/MM/dd: 2011-05-01
C#
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));
   }
}
// The example displays the following output:
//       Original Short Date Pattern:
//          M/d/yyyy: 5/1/2011
//       Revised Short Date Pattern:
//          yyyy/MM/dd: 2011-05-01

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Date

History

Reason

December 2010

Revised the first example and added the second example.

Customer feedback.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
incorrect chinese localization      jlechem ... R Petrusha - MSFT   |   Edit   |   Show History

For some reason the chinese and japanese localizations are incorrect. They don't use the kanjii symbols and instead are yyyy/M/d according to a chinese co worker they kanjii should be used instead.

Localization and Kanji

The format strings that define the format produced by calls to the date and time ToString methods are not localized. Only the Latin characters listed in the Standard Date and Time Format Strings topic at http://msdn.microsoft.com/en-us/library/az4se3k1.aspx and in the Custom Date and Time Format Strings topic at http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx are supported; Kanji characters are not.

In addition, regardless of the character set specified by the NumberFormatInfo.NativeDigits property of a CultureInfo object, only the Basic Latin digits U+0030 through U+0039 are used in formatting and parsing operations. Date and time elements that can be localized include the names of days of the week and the abbreviated names of days of the week, the names of eras, the names of days of the month and the abbreviated names of days of the month, the first character of the AM/PM designators, and the AM/PM designators.

--Ron Petrusha
Common Language Runtime User Education
Microsoft Corporation

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker