NodaTime: From server to client

烂漫一生 提交于 2019-12-11 09:17:41

问题


I am using NodaTime I am storing time information in the form of Ticks since epoch.

However, I want to pass the number of milliseconds since unix epoch back to the client browser, so I can construct a javascript Date() object. Is there not a way to do this?

If this method is out of the question, does anyone else have a better idea?

p.s. I'm tired of messing with strings because I always have to wonder how they will be interpreted.


回答1:


There are 10 000 ticks per millisecond, and NodaTime has a constant for this, viz NodaConstants.TicksPerMillisecond.

If you are store time in an Instant object, you can get the ticks via the Instant.Ticks property.

And if necessary, the ZonedDateTime can be converted to an Instant via the .ToInstant() method

PS: v1.2 claims to have additional Xml and JSON serialization capabilities - possibly this will help you format your js date.



来源:https://stackoverflow.com/questions/22240872/nodatime-from-server-to-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!