Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't believe this is possible - there is no ability to set the timezone on a Date object after it is created.</p> <p>And in a way this makes sense - conceptually (if perhaps not in implementation); per <a href="http://en.wikipedia.org/wiki/Unix_timestamp" rel="noreferrer">http://en.wikipedia.org/wiki/Unix_timestamp</a> (emphasis mine):</p> <blockquote> <p>Unix time, or POSIX time, is a system for describing instants in time, defined as the number of seconds elapsed since midnight <strong>Coordinated Universal Time (UTC)</strong> of Thursday, January 1, 1970.</p> </blockquote> <p>Once you've constructed one it will represent a certain point in "real" time. The time zone is only relevant when you want to convert that abstract time point into a human-readable string.</p> <p>Thus it makes sense you would only be able to change the actual time the Date represents in the constructor. Sadly it seems that there is no way to pass in an explicit timezone - and the constructor you are calling (arguably correctly) translates your "local" time variables into GMT when it stores them canonically - so there is no way to use the <code>int, int, int</code> constructor for GMT times.</p> <p>On the plus side, it's trivial to just use the constructor that takes a String instead. You don't even have to convert the numeric month into a String (on Firefox at least), so I was hoping a naive implementation would work. However, after trying it out it works successfully in Firefox, Chrome, and Opera but fails in Konqueror ("Invalid Date") , Safari ("Invalid Date") and IE ("NaN"). I suppose you'd just have a lookup array to convert the month to a string, like so:</p> <pre><code>var months = [ '', 'January', 'February', ..., 'December']; function createGMTDate(xiYear, xiMonth, xiDate) { return new Date(months[xiMonth] + ' ' + xiDate + ', ' + xiYear + ' 00:00:00 GMT'); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload