开发者

Do you need to convert a JavaScript Date to UTC before calling getVarDate?

I'm working with 开发者_如何学GoActiveX controls in Internet Explorer and need to pass dates to the ActiveX methods that take dates as parameters. The methods expect dates to be of type, VT_DATE and I can produce VT_DATE values by using the JScript getVarDate method on a Date object.

Do I need to first convert a JavaScript Date to UTC before calling getVarDate?

I assume that the answer is no, but I am not 100% certain and don't know why.

Sample JavaScript code to illustrate what I'm talking about:

var myDate = new Date(); // Gives me a JavaScript Date object.
console.log(myDate.toString()); // Outputs a string representing the date in the local time zone.
console.log(myDate.toUTCString()); // Outputs a string representing the date in UTC.

var myVT_DATE = myDate.getVarDate();
myActiveXControl.someMethodWantingVT_DATE(myVT_DATE);


If there's any chance of your site being used in more than one timezone, I would recommend using toUTCString(). Each browser will return the local date/time by default (as you've experienced). This may not seem like a big deal until...

You get deep into the project and it all-of-the-sudden really matters and you're faced with rewrites.

... or worse ...

Your site has been live for months and you now have some need (like reporting) that requires those dates and you realize that you don't know which timezone each date was created in.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜