NodaTime: From server to client

2019-08-09 10:10发布

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条回答
淡お忘
2楼-- · 2019-08-09 10:28

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.

查看更多
登录 后发表回答