gpt4 book ai didi

javascript - 无效日期 : Converting UTC to local

转载 作者:行者123 更新时间:2023-12-03 08:00:46 25 4
gpt4 key购买 nike

我正在使用 Moment.js 在 Razor View 页面中将 UTC 时间转换为本地时间。日期时间格式为 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 方法。

关于javascript - 无效日期 : Converting UTC to local,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34587727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com