問題描述
我正在使用具有本地化和全球化的 ASP.NET 應用程序.在給定用戶環境的情況下,我很難理解如何讓 JavaScript 中的 Date() 函數正常工作.我的用戶群分布在墨西哥(西班牙語)和美國(英語)之間.由于墨西哥日期格式是 dd/mm/yyyy 而英文格式是 mm/dd/yyyy,標準 Date(strDate) javascript 構造函數對我不起作用.
I'm working with an ASP.NET app with localization and globalization. I'm having some difficulty understanding how to get the Date() function in javascript to work properly given the user's environment. My user base is split between Mexico (spanish) and the US (english). Since the Mexico date format is dd/mm/yyyy and the english format is mm/dd/yyyy, the standard Date(strDate) javascript constructor does not work for me.
有誰知道處理 javascript 日期值的全球化/本地化的最佳方法?我有一些業務規則要強制執行,例如 dateA 必須比 dateB 早 90 天,并且 dateB 不能超過今天.
Does anyone know the best way to handle globalization/localization of a javascript Date value? I have some business rules to enforce like dateA must be 90 days prior to dateB and dateB cannot exceed today.
推薦答案
看看datejs,它可以很好地處理本地化.它帶有很多全球化設置.您只需加載當前 CultureInfo 的全球化設置,而 datejs 會負責其余的工作.
Take a look at datejs, it handles localization very nicely. It comes with a lot of globalization setups. You just load the globalization setup of your current CultureInfo and datejs takes care of the rest.
這篇關于Javascript 日期本地化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!