I want to use the javascript's toISOString() function and ignore the timezone.
var someDate; // contains "Tue May 26 2015 14:00:00 GMT+0100 (Hora de Verão de GMT)"
dateIWant = someDate.toISOString(); // turns out "2015-05-26T13:00:00.000Z"
The date to convert is Tue May 26 2015 14:00:00 GMT+0100 (Hora de Verão de GMT) but the converted date is 2015-05-26T13:00:00.000Z.
So, I need the date in the yyyy-MM-ddTHH:mm:ss:msZ but as you can see above it applies the timezone and changes the hour from 14 to 13.
How to achieve this?
EDIT
I am working on a C# MVC project and I can send the date as it is and manipulate it in the C#. It is my current solution but I am looking for a client side one.
Based on the polyfill for Date.prototype.toISOString found at MDN's Date.prototye.toISOString:
if (!Date.prototype.toLocalISOString) {
  (function() {
    function pad(number) {
      if (number < 10) {
        return '0' + number;
      }
      return number;
    }
    Date.prototype.toLocalISOString = function() {
      return this.getFullYear() +
        '-' + pad(this.getMonth() + 1) +
        '-' + pad(this.getDate()) +
        'T' + pad(this.getHours()) +
        ':' + pad(this.getMinutes()) +
        ':' + pad(this.getSeconds()) +
        '.' + (this.getMilliseconds() / 1000).toFixed(3).slice(2, 5) +
        'Z';
    };
  }());
}
So just use this toLocalISOString instead of toISOString.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With