問題描述
我正在使用具有本地化和全球化的 ASP.NET 應(yīng)用程序.在給定用戶環(huán)境的情況下,我很難理解如何讓 JavaScript 中的 Date() 函數(shù)正常工作.我的用戶群分布在墨西哥(西班牙語)和美國(英語)之間.由于墨西哥日期格式是 dd/mm/yyyy 而英文格式是 mm/dd/yyyy,標(biāo)準(zhǔn) Date(strDate) javascript 構(gòu)造函數(shù)對(duì)我不起作用.
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 日期值的全球化/本地化的最佳方法?我有一些業(yè)務(wù)規(guī)則要強(qiáng)制執(zhí)行,例如 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,它可以很好地處理本地化.它帶有很多全球化設(shè)置.您只需加載當(dāng)前 CultureInfo 的全球化設(shè)置,而 datejs 會(huì)負(fù)責(zé)其余的工作.
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.
這篇關(guān)于Javascript 日期本地化的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!