开发者

How to put a date value as a number in a jscript array instead of using new Date(2008, 1 ,1)?

I have an array of dates that I am populating adding the dates creating the types and calling their constructor like this: new Date(2008, 1, 1)

I was wondering if there is a better way to do this? I am guessing that I can use the numeric representation of Date and put that into the array on the server side and send this array down to the client. I feel that the array with the numbers will be smaller and will result a faster running jscript on the client.

I would like to know how it is possible and if this results better performanc开发者_运维知识库e at all?

I am fairly new to jscript.


You can use dateObject.getTime() to get the number of milliseconds since 1970 Jan 1. Use dateObject.setTime(time) for the reverse operation.

Whether it has higher performance or not, you need to profile it. I think there isn't much difference.


Use KennyTM's recommendation. Also, if there's a date after which you're sure all of the dates will fall, remember that when you're storing the numerical representation. Only store the delta between the base date and the actual date. The numbers you have to send over the wire will be smaller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜