2013 m. rugsėjo 12 d., ketvirtadienis

Datos formatas pagal lokalią kalbą JavaScript ir ASP.NET

Problema: atnaujinant duomenis su JavaScript, dažnai reikia išlaikyti datos formatą pagal lokalią kalbą.

Sprendimas:

var d = new Date(MeetDate).localeFormat("d"); - JavaScript

< % #  Eval("MeetDate", " { 0 : d } ") % > - ASP.NET

Daugiau: http://www.asp.net/AJAX/Documentation/Live/ClientReference/Global/JavascriptTypeExtensions/DateTypeExt/default.aspx

In Chapter 6: ASP.NET AJAX Localization, on page 289, we have a tip on Data Format Strings. It states that “the data format strings available for the Date and Number types in JavaScript are the same as those that are available in .NET for the DateTime and Double types.” This is incorrect.
The format strings that are allowed for Number types are the following:
  • c or C: Currency
  • p or P: Percentage
  • d or D“: Decimal (# number of digits)
  • n or N“: Numeric (# number of digits after decimal)
- e, f, g, r, x, and custom format strings are not supported
The standard format strings that are allowed for the Date type are the following:
  • d: Short date pattern
  • D: Long date pattern
  • t: Short time pattern
  • T: Long time pattern
  • F: Full date/time pattern (long time)
  • m or M: Month day pattern
  • s: Sortable date/time pattern
  • y or Y: Year month pattern
- the standard format strings: f, F, g, G, O, o, R, r, u, U are not supported. However, custom format strings that use the “mmm”, “yyyy”, “hh”, etc. formats are supported. You can build your own date format string.

http://seejoelprogram.wordpress.com/2008/08/07/supported-number-and-datetime-format-strings-in-aspnet-ajax/




Kaip iš DateTime gauti datos formatą JavaScript'e:

DateAdded: (new Date(parseFloat(result.d[i].auditdate.slice(6, 19)))).localeFormat("d")

čia 6,19 iš DateTime formato nuima pradžią ir pabaigą.

1 komentaras:

  1. EDNIM kietasis šampūnas yra rankų darbo, be jokių sintetinių komponentų, natūralus naujos kartos kietasis šampūnas. www.ednim.lt

    AtsakytiPanaikinti