How to convert a hard coded date to standard GMT format

I need to convert a hard-coded date to standard GMT format. How can i do this? The date I have has the following format: var myDate = 'dd | mm | yyyy '; There is no time or day description in the date. Just enter the string "dd | mm | yyyy". Is there any way to convert it to GMT?

Thanks in advance.

+3
source share
2 answers
a = '22/02/2014'.split('/')
d = new Date(a[2],parseInt(a[1], 10) - 1,a[0])
//Sat Feb 22 2014 00:00:00 GMT+0530 (India Standard Time)

You now have a javascript date object in d

utc = d.getUTCDate() + "/" + (d.getUTCMonth() + 1 ) + "/" + d.getUTCFullYear();
//"21/2/2014" for an accurate conversion to UTC time of day is a must.

If you are in India, a Javascript object Datewill have timeZoneOffset 330. Thus, it is not possible to save a javascript object Datewith a time zone GMTif your system time GMT.

, Date , localTimezone , GMT

pseudoGMT = new Date( Date.parse(d) + d.getTimezoneOffset() * 60 * 1000);
//Fri Feb 21 2014 18:30:00 GMT+0530 (India Standard Time)

, .

+2

:

var myDate = "21|01|2014";
var data = myDate.match(/(\d{2})\|(\d{2})\|(\d{4})/);
var date = new Date(data[3], data[2] - 1, data[1]);

, 0, january = 0

: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

+1

All Articles