月份名称序列化本地特定
根据 Coldfusion 文档,SerializeJSON 将日期转换为可由 JavaScript Date 对象轻松解析的字符串。 我刚刚序列化了一个查询,JavaScript 无法解析日期列,因为月份名称是本地特定的序列化返回 Mai,JavaScript 无法理解这一点。 Javascript 仅接受英文月份名称。我现在是否需要像刚才那样将本地特定月份名称手动替换为英文翻译才能轻松将字符串解析为 JavaScript Date 对象?
最好的, 伯恩哈德
according to the coldfusion docs SerializeJSON converts Dates to strings which can easily be parsed by JavaScript Date objects.
I just serialized a query and JavaScript could not parse the Date columns because the name of the month was serialized local specfic returning Mai, what is not understood by JavaScript. Javascript only accepts english month names. Do I now - as I just did - have to replace the local specific month name manually with it's english translation to easily parse the string to a JavaScript Date object?
Best,
Bernhard
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试在服务器上处理此问题,方法是使用
setLocale('en_us')
在序列化时强制查询英语版本 - 不太理想,但它可能会完成工作。我认为这可以根据请求设置。请参阅此处的信息:http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fa3.html希望有所帮助。
You could try and deal with this on the server by using
setLocale('en_us')
to force English language versions of your query when serialised - not ideal but it might get the job done. I think this can be set per request. See info here: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7fa3.htmlHope that helps.
此答案另一个问题建议您也许可以使用datejs ,然后使用适当的本地化来解析您的字符串,而不是用英语。
This answer to another question suggests that perhaps you could use datejs and then use the appropriate localization to parse your strings natively rather than in English.
我有一个解决方案
在coldfusion管理员中将此
-Duser.language=en -Duser.region=US
添加到JVM agruments中。 (并重新启动服务)您告诉 JVM 引擎不要使用计算机区域设置,而是使用“正常”英语区域设置。当您在更改后使用 SerializeJSON 时,它将生成带有英语月份名称的日期。
我没有发现此更改有任何不需要的副作用。
I have a solution
In the coldfusion administrator add this
-Duser.language=en -Duser.region=US
to the JVM agruments. (And restart the service) You tell the JVM engine not to use the machine locale but to use the 'normal' english locale.When you use SerializeJSON after the change it will generate dates with the enlish month names.
I haven't found any unwanted side effects with this change.