-1

I have a date string CStartDate as '3/23/2014' that I am getting from siebel side.I need to convert it to UTC time zone where timeoffset becomes zero.I have tried something like this:

var a = CStartDate.split('/');

var c = a[0];
a[0] = a[1];
a[1] = c; 

var tacStartDate = new Date(a[2],parseInt(a[1], 10) - 1,a[0]);
alert(tacStartDate);

This alert returns as 'Sun Mar 23 2014 00:00:00 GMT+0530 (India Standard Time)', but I don't want that offset GMT+0530 (India Standard Time), rather I want it only to be 'Sun Mar 23 2014 00:00:00 GMT+0000'.I want this as a date object which will be indicating date of GMT, not any other location. How can I achieve that?

Thanks in advance.

1
  • 1
    I would reccommend moment.js for this. Makes life a whole lot easier. Commented Mar 26, 2014 at 9:21

2 Answers 2

1

try toISOString() on the Date object. If using less than ECMAScript 5, there is a polyfill for the function

if ( !Date.prototype.toISOString ) {
  ( function() {

    function pad(number) {
      if ( number < 10 ) {
        return '0' + number;
      }
      return number;
    }

    Date.prototype.toISOString = function() {
      return this.getUTCFullYear() +
        '-' + pad( this.getUTCMonth() + 1 ) +
        '-' + pad( this.getUTCDate() ) +
        'T' + pad( this.getUTCHours() ) +
        ':' + pad( this.getUTCMinutes() ) +
        ':' + pad( this.getUTCSeconds() ) +
        '.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice( 2, 5 ) +
        'Z';
    };

  }() );
}
Sign up to request clarification or add additional context in comments.

Comments

0

There is an UTC method of Date. It should be as simple as:

new Date(Date.UTC(a[2],parseInt(a[1], 10) - 1,a[0]));

2 Comments

Hi blue I tried it and it returns as 'Sun Mar 23 2014 05:30:00 GMT+0530 (India Standard Time)'. but my concern is its anyway producing the local time which I don't want. I want an object which will give me date lets say if I am staying at GMT, then it will produce something like 'Sun Mar 23 2014 00:00:00 GMT+0000 (GMT)'.I want this time object.In the requirement I can't change the date location, so if i use above method it will produce local time not the GMT.How can i achieve that?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.