Compartir a través de


Sys.CultureInfo.dateTimeFormat Property

Gets an object that contains an array of culture-sensitive formatting and parsing string values that can be applied to Date type extensions.

var cultureObject = Sys.CultureInfo.CurrentCulture;
var dtfObject = cultureObject.dateTimeFormat;

Return Value

An object that contains an array of culture-sensitive formatting strings.

Remarks

Use the dateTimeFormat field to retrieve an object that contains an array of formatting strings that are based on the current culture or on the invariant culture. Each formatting string can be used to specify how to format Date type extensions.

Example

The following example shows how to use the dateTimeFormat field of the Sys.CultureInfo class based on the current culture. The culture attribute of the <configuration> section in the Web.config file must also be set to "auto". For more information about culture settings, see Walkthrough: Globalizing a Date by Using Client Script.

<script type="text/javascript">
    // Create the CurrentCulture object
    var cultureObject = Sys.CultureInfo.CurrentCulture;
    // Get the name field of the CurrentCulture object
    var cultureName = cultureObject.name;
    // Get the dateTimeFormat object from the CurrentCulture object
    var dtfObject = cultureObject.dateTimeFormat;
    // Create an array of format types
    var myArray = ['AMDesignator', 'Calendar', 'DateSeparator', 'FirstDayOfWeek',
                   'CalendarWeekRule', 'FullDateTimePattern', 'LongDatePattern', 
                   'LongTimePattern', 'MonthDayPattern', 'PMDesignator', 'RFC1123Pattern', 
                   'ShortDatePattern', 'ShortTimePattern', 'SortableDateTimePattern', 
                   'TimeSeparator', 'UniversalSortableDateTimePattern', 'YearMonthPattern', 
                   'AbbreviatedDayNames', 'ShortestDayNames', 'DayNames', 
                   'AbbreviatedMonthNames', 'MonthNames', 'IsReadOnly',
                   'NativeCalendarName', 'AbbreviatedMonthGenitiveNames', 
                   'MonthGenitiveNames'];

    var result = 'Culture Name: ' + cultureName;
    for (var i = 0, l = myArray.length; i < l; i++) {
        var arrayVal = myArray[i];
        if (typeof(arrayVal) !== 'undefined') {
            result += "<tr><td>" + arrayVal + "</td><td>" + eval("dtfObject." + arrayVal) + '</td></tr>';
        }
    }
    var resultHeader = "<tr><td><b>FormatType</b></td><td><b>FormatValue</b></td></tr>"
    $get('Label1').innerHTML = "<table border=1>" + resultHeader + result +"</table>";

    var d = new Date();
    $get('Label2').innerHTML = "<p/><h3>dateTimeFormat Example: </h3>" + 
    d.localeFormat(Sys.CultureInfo.CurrentCulture.dateTimeFormat.FullDateTimePattern);
 </script>
<script type="text/javascript">
    // Create the CurrentCulture object
    var cultureObject = Sys.CultureInfo.CurrentCulture;
    // Get the name field of the CurrentCulture object
    var cultureName = cultureObject.name;
    // Get the dateTimeFormat object from the CurrentCulture object
    var dtfObject = cultureObject.dateTimeFormat;
    // Create an array of format types
    var myArray = ['AMDesignator', 'Calendar', 'DateSeparator', 'FirstDayOfWeek',
                   'CalendarWeekRule', 'FullDateTimePattern', 'LongDatePattern', 
                   'LongTimePattern', 'MonthDayPattern', 'PMDesignator', 'RFC1123Pattern', 
                   'ShortDatePattern', 'ShortTimePattern', 'SortableDateTimePattern', 
                   'TimeSeparator', 'UniversalSortableDateTimePattern', 'YearMonthPattern', 
                   'AbbreviatedDayNames', 'ShortestDayNames', 'DayNames', 
                   'AbbreviatedMonthNames', 'MonthNames', 'IsReadOnly',
                   'NativeCalendarName', 'AbbreviatedMonthGenitiveNames', 
                   'MonthGenitiveNames'];

    var result = 'Culture Name: ' + cultureName;
    for (var i = 0, l = myArray.length; i < l; i++) {
        var arrayVal = myArray[i];
        if (typeof(arrayVal) !== 'undefined') {
            result += "<tr><td>" + arrayVal + "</td><td>" + eval("dtfObject." + arrayVal) + '</td></tr>';
        }
    }
    var resultHeader = "<tr><td><b>FormatType</b></td><td><b>FormatValue</b></td></tr>"
    $get('Label1').innerHTML = "<table border=1>" + resultHeader + result +"</table>";

    var d = new Date();
    $get('Label2').innerHTML = "<p/><h3>dateTimeFormat Example: </h3>" + 
    d.localeFormat(Sys.CultureInfo.CurrentCulture.dateTimeFormat.FullDateTimePattern);
 </script>

See Also

Reference

Sys.CultureInfo Class

Other Resources

Language Reference