SharpStyle Labs

Creativity is coming up with new things. Innovation is doing new things. We make software that helps you do both.

  • Pages

  • a

  • Archives

JavaScript, Date, toUTCString()

Posted by sharpstyle on April 12, 2007

Consider the following code

var a = new Date();
var b = new Date(a.toUTCString());
alert(b – a);

My expectation that it will return 0, but it was consistently returning negative values as if b was an earlier date than a.

How is that possible? toUTCString() drops milliseconds, which essentially makes b an earlier date than a.

~Mike

Advertisement

One Response to “JavaScript, Date, toUTCString()”

  1. No Comment said

    Because a is not UTC and will have a different value than b which is UTC.

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.