无效日期:将 UTC 转换为本地
Invalid Date : Converting UTC to local
我正在使用 Moment.js 在我的 Razor 视图中将 UTC 时间转换为本地时间 Page.The 日期时间格式为 2015-12- 30 10:13:11.527 这是我的语法 ..
<td><script>document.write(moment.utc('@data.StatusDateTime').local())</script></td>
但是我收到无效日期作为转换值..如何更正它?
如果 StatusDateTime
是 DateTime 字段,您可能希望在传递给 moment.utc
方法之前将其格式化:
moment.utc('@user.StatusDateTime.ToUniversalTime().ToString("o")').local()
另请注意,我已将此处的 StatusDateTime
转换为 UTC 以确保我们具有正确的值,但如果该字段已经是 UTC 日期,则无需调用 ToUniversalTime
方法就可以了。
我正在使用 Moment.js 在我的 Razor 视图中将 UTC 时间转换为本地时间 Page.The 日期时间格式为 2015-12- 30 10:13:11.527 这是我的语法 ..
<td><script>document.write(moment.utc('@data.StatusDateTime').local())</script></td>
但是我收到无效日期作为转换值..如何更正它?
如果 StatusDateTime
是 DateTime 字段,您可能希望在传递给 moment.utc
方法之前将其格式化:
moment.utc('@user.StatusDateTime.ToUniversalTime().ToString("o")').local()
另请注意,我已将此处的 StatusDateTime
转换为 UTC 以确保我们具有正确的值,但如果该字段已经是 UTC 日期,则无需调用 ToUniversalTime
方法就可以了。