tags:

views:

20

answers:

2

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 performance at all?

I am fairly new to jscript.

+2  A: 

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.

KennyTM
+1  A: 

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.

lance
Thanks for the suggestion. I am guessing on the client I will need to add some processing code to reconstruct my array to have the correct date
gyurisc