Displaying proper date format depending on culture

后端 未结 8 1247
感情败类
感情败类 2021-01-06 06:40

I am using a control for a popup calendar date picker. This uses a javascript function, SetText, to set the textbox to the given date. I can\'t change anything in the cale

相关标签:
8条回答
  • 2021-01-06 07:09

    You are using the Microsoft Ajax Framework, this framework defines a set of "client-side type extensions" which provide added functions or "extensions" to the JavaScript base types.

    The Date Type Extensions is what you're looking for, specifically the Date.parseLocale function.

    With this function you can parse a string, using a given format.

    You can synchronize your server-side and client-side culture by setting the ScriptManager.EnableScriptGlobalization property to true, and use the Date.parseLocale function without specifying any format.

    Give a look to this article:

    • Walkthrough: Globalizing a Date by Using Client Script
    0 讨论(0)
  • 2021-01-06 07:14

    If you control the backend, why not just send a timestamp and push it into Date object?

    As for formatting on the client side, since I was already using Dojo, I solved this problem by using dojo.date.locale.format. It was completely painless.

    • Locale is detected automatically or can be set arbitrarily.
    • Shorthand format options (e.g.: long short)
    • Data selectors (e.g.: time, date)
    • Ability to specify an arbitrary date/time pattern (probably not application to this application, but still useful).

    Tutorial: http://docs.dojocampus.org/dojo/date/locale
    API doc: http://api.dojotoolkit.org/jsdoc/1.3/dojo.date.locale.format
    Date format descriptions: http://www.unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns

    0 讨论(0)
提交回复
热议问题