Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > GMT Date Format Anomaly

Reply
Thread Tools

GMT Date Format Anomaly

 
 
clintonG
Guest
Posts: n/a
 
      12-26-2004
When the following code is run on Sat Dec 25 2004 19:54:18 GMT-0600 (Central
Standard Time)

var today = new Date();
var GMTDate = today.toGMTString();
document.write("GMTDate: " + GMTDate);

The code returns:
Sun, 26 Dec 2004 19:54:18 GMT (the next day after the code was actually run)

Please advise why the day is in the future and suggest how to get the
correct GMT date format.

<%= Clinton Gallagher


 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      12-26-2004
clintonG said:
>
>When the following code is run on Sat Dec 25 2004 19:54:18 GMT-0600 (Central
>Standard Time)
>
>var today = new Date();
>var GMTDate = today.toGMTString();
>document.write("GMTDate: " + GMTDate);
>
>The code returns:
>Sun, 26 Dec 2004 19:54:18 GMT (the next day after the code was actually run)
>
>Please advise why the day is in the future and suggest how to get the
>correct GMT date format.


Are you sure it shows the time as 19:54:18?
At that time CST it *is* the next day in GMT.

 
Reply With Quote
 
 
 
 
clintonG
Guest
Posts: n/a
 
      12-26-2004
Thank you for your attention. We can scratch that time for now noting the
discrepancy may be because I copied and pasted to make things easier to read
but read or run the following please...

//Example A
//Returns: Sun Dec 26 2004 10:49:25 GMT-0600 (Central Standard Time)
var expDate = new Date( );
document.write("expDate: " + expDate + "<br />");


//Example B
//Returns: Sun, 26 Dec 2004 16:49:25 GMT
var today = new Date( );
var myDateString = today.toGMTString( );
document.write("myDateString: " + myDateString);

I understand what is going on now. Example A uses the Date method that
returns time as CST which is GMT-0600 hours (6 hours less than GMT) so
sitting in front of a computer in a region that uses CST (me) and running
Example B at a time of day less than 6 hours from midnight in Greenwich will
indicate the date as the 'next day' when the the Date( ) method is overriden
by the toGMTString( ) method.

<%= Clinton Gallagher




"Lee" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> clintonG said:
> >
> >When the following code is run on Sat Dec 25 2004 19:54:18 GMT-0600

(Central
> >Standard Time)
> >
> >var today = new Date();
> >var GMTDate = today.toGMTString();
> >document.write("GMTDate: " + GMTDate);
> >
> >The code returns:
> >Sun, 26 Dec 2004 19:54:18 GMT (the next day after the code was actually

run)
> >
> >Please advise why the day is in the future and suggest how to get the
> >correct GMT date format.

>
> Are you sure it shows the time as 19:54:18?
> At that time CST it *is* the next day in GMT.
>



 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      12-26-2004
On Sun, 26 Dec 2004 11:03:47 -0600, clintonG
<(E-Mail Removed)> wrote:

[snip]

> var today = new Date( );
> var myDateString = today.toGMTString( );


Just so you know, the toGMTString method is deprecated in favour of the
toUTCString method. The effect if the same, though.

[snip]

Mike


Please don't top-post.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
 
Reply With Quote
 
clintonG
Guest
Posts: n/a
 
      12-26-2004
Thank you. I'll try that out right now...

<%= Clinton Gallagher

"Michael Winter" <(E-Mail Removed)> wrote in message
newspsjmlj2uox13kvk@atlantis...
> On Sun, 26 Dec 2004 11:03:47 -0600, clintonG
> <(E-Mail Removed)> wrote:
>
> [snip]
>
> > var today = new Date( );
> > var myDateString = today.toGMTString( );

>
> Just so you know, the toGMTString method is deprecated in favour of the
> toUTCString method. The effect if the same, though.
>
> [snip]
>
> Mike
>
>
> Please don't top-post.
>
> --
> Michael Winter
> Replace ".invalid" with ".uk" to reply by e-mail.



 
Reply With Quote
 
clintonG
Guest
Posts: n/a
 
      12-26-2004
So-called 'we support standards' FireFraud 0.9.3 returns the text GMT in the
string returned by the toUTCString method but the 'evil' IE returns UTC as
expected.

var today = new Date();
var UTCDateTime = today.toUTCString();
document.write("<b>UTCDateTime: </b>" + UTCDateTime);

<%= Clinton Gallagher


"Michael Winter" <(E-Mail Removed)> wrote in message
newspsjmlj2uox13kvk@atlantis...
> On Sun, 26 Dec 2004 11:03:47 -0600, clintonG
> <(E-Mail Removed)> wrote:
>
> [snip]
>
> > var today = new Date( );
> > var myDateString = today.toGMTString( );

>
> Just so you know, the toGMTString method is deprecated in favour of the
> toUTCString method. The effect if the same, though.
>
> [snip]
>
> Mike
>
>
> Please don't top-post.
>
> --
> Michael Winter
> Replace ".invalid" with ".uk" to reply by e-mail.



 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      12-26-2004
On Sun, 26 Dec 2004 20:20:47 GMT, clintonG
<(E-Mail Removed)> wrote:

Please don't top-post.

> So-called 'we support standards' FireFraud 0.9.3 returns the text GMT in
> the string returned by the toUTCString method but the 'evil' IE returns
> UTC as expected.


There is no defined output format for the method:

"This function returns a string value. The contents of the string
are implementation-dependent, but are intended to represent the
Date in a convenient, human-readable form in UTC."

-- Section 15.9.5.42, ECMA-262

If you need a specific format, it's best to do it yourself.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
 
Reply With Quote
 
Lee
Guest
Posts: n/a
 
      12-26-2004
clintonG said:
>
>So-called 'we support standards' FireFraud 0.9.3 returns the text GMT in the
>string returned by the toUTCString method but the 'evil' IE returns UTC as
>expected.


Welcome to the newsgroup.

Referring to popular browsers as "Firefraud" or "Netscrape", etc is not really a
good way to ensure your popularity or that you will receive the best possible
answers to your questions. You're sure to **** off a few and make a few more
write you off as a childish twit.

Pointing out that IE "makes the trains run on time" isn't going to change many
opinions, anyway.

 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      12-28-2004
JRS: In article <R%qzd.147900$(E-Mail Removed)-kc.rr.com>, dated
Sun, 26 Dec 2004 04:22:09, seen in news:comp.lang.javascript, clintonG
<(E-Mail Removed)> posted :

>When the following code is run on Sat Dec 25 2004 19:54:18 GMT-0600 (Central
>Standard Time)


Please note that this is an international newsgroup. Terms such as
"Central Standard Time" are therefore not generally helpful, since we do
not know of what it might be the centre. Russia? Australia?

>var today = new Date();
>var GMTDate = today.toGMTString();
>document.write("GMTDate: " + GMTDate);
>
>The code returns:
>Sun, 26 Dec 2004 19:54:18 GMT (the next day after the code was actually run)
>
>Please advise why the day is in the future and suggest how to get the
>correct GMT date format.


There is something wrong with your system or its operator.


Note : this response to your article is formatted in accordance with
standard usenet recommendations endorsed by the Wednesday edition of the
FAQ (which you should have read) of this newsgroup.

Note : Americans, and the software that they originate, traditionally
have a very poor understanding of date and time, except as it applies in
CONUS, maybe AK & HI, and just possibly CA (the region which prevents AK
from being an island). It is not only non-Americans that need to allow
for that.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
 
Reply With Quote
 
Mark Preston
Guest
Posts: n/a
 
      12-28-2004
clintonG wrote:

> So-called 'we support standards' FireFraud 0.9.3 returns the text GMT in the
> string returned by the toUTCString method but the 'evil' IE returns UTC as
> expected.
>

There is no defined output format for UTC (which is an *internal* means
of representing time set at GMT for general use - pureply "cosmetic").
The correct display format in ALL cases will be "GMT" and that is what
you should see.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Re: Sorting Date/Time Format "Tue, 04 May 2004 03:13:29 GMT" Peter Rilling ASP .Net 0 05-04-2004 07:29 PM
Date Format - best way of converting a string into a date format Brian Candy ASP .Net 2 02-18-2004 02:13 PM
Time/Date format and changing time to GMT Shaiboy_UK ASP General 1 10-19-2003 01:04 PM
Time/Date format and changing time to GMT Shaiboy_UK ASP .Net 0 10-18-2003 11:30 PM



Advertisments