what JavaScript date gives you?

In my previous post I was trying to format date, and I noticed that I was not getting it correctly. Why was that, I assembled a small script to test all accessor methods provided by Date. Here is that code.

var today = new Date();
var message = "All accessor methods of date \n\n\n" +
    "getDate(): " + today.getDate() + "\n" +
    "getDay(): " + today.getDay() + "\n" +
    "getFullYear(): " + today.getFullYear() + "\n" +
    "getHours(): " + today.getHours() + "\n" +
    "getMilliseconds(): " + today.getMilliseconds() + "\n" +
    "getMinutes(): " + today.getMinutes() + "\n" +
    "getMonth(): " + today.getMonth() + "\n" +
    "getSeconds(): " + today.getSeconds() + "\n" +
    "getTime(): " + today.getTime() + "\n" +
    "getTimezoneOffset(): " + today.getTimezoneOffset() + "\n" +
    "getUTCDate(): " + today.getUTCDate() + "\n" +
    "getUTCDay(): " + today.getUTCDay() + "\n" +
    "getUTCFullYear(): " + today.getUTCFullYear() + "\n" +
    "getUTCHours(): " + today.getUTCHours() + "\n" +
    "getUTCMilliseconds(): " + today.getUTCMilliseconds() + "\n" +
    "getUTCMinutes(): " + today.getUTCMinutes() + "\n" +
    "getUTCMonth(): " + today.getUTCMonth() + "\n" +
    "getUTCSeconds(): " + today.getUTCSeconds() + "\n" +
    "getYear(): " + today.getYear() + "\n" +
    "toDateString(): " + today.toDateString() + "\n" +
    "toGMTString(): " + today.toGMTString() + "\n" +
    "toLocaleDateString(): " + today.toLocaleDateString() + "\n" +
    "toLocaleString(): " + today.toLocaleString() + "\n" +
    "toString(): " + today.toString() + "\n" +
    "toTimeString(): " + today.toTimeString() + "\n" +
    "toUTCString(): " + today.toUTCString();
alert(message);

I captured the alert dialog, provided below.

date.chrome date.ie

I changed the browser, and looked at any changes, and there were some, which I have listed below. So when working with them on different browsers, care must be taken.

Accessor Google Chrome Internet Explorer 10
toDateString() Fri 08 Feb 2013 Fri 8 Feb 2013
toGMTString() Fri, 08 Feb 2013 11:00:42 GMT Fri, 8 Feb 2013 11:00:42 UTC
toLocaleDateString() 2/8/2013 Friday, February 8, 2013
toLocaleString() 2/8/2013 4:00:42 PM Friday, February 8, 2013 4:00:42 PM
toString() Fri Feb 08 2013 16:00:42 GMT+0500 (Local Standard Time) Fri Feb 8 16:00:42 UTC+0500 2013
toTimeString() 16:00:42 GMT+0500 (Local Standard Time) 16:00:42 UTC+0500
toUTCString() Fri, 08 Feb 2013, 11:00:42 GMT Fri, 8 Feb 2013 11:00:42 UTC

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.