2

Possible Duplicate:
Generate an RFC 3339 timestamp similar to Google Tasks API?

I'm writing a javascript code to parse events from an XML file and insert them into google calendar. I'm facing a problem in converting my regular UTC dates to google calendar DateTime format.

My date appears in this format (UTC):

Mon Apr 02 2013 15:14:33 GMT+0300 (Arab Standard Time)

While the format I want to convert to is (rfc 3999):

2013-1-16T10:00:00.000-07:00

I tried using methods like date.format() or getDateTime() this but it never worked

Any help is greatly appreciated

Community
  • 1
  • 1
user1851026
  • 21
  • 1
  • 1
  • 2

1 Answers1

6

see Generate an RFC 3339 timestamp similar to Google Tasks API?:

/* use a function for the exact format desired... */
function ISODateString(d){
 function pad(n){return n<10 ? '0'+n : n}
 return d.getUTCFullYear()+'-'
      + pad(d.getUTCMonth()+1)+'-'
      + pad(d.getUTCDate())+'T'
      + pad(d.getUTCHours())+':'
      + pad(d.getUTCMinutes())+':'
      + pad(d.getUTCSeconds())+'Z'}

var d = new Date();
print(ISODateString(d)); // prints something like 2009-09-28T19:03:12Z
Community
  • 1
  • 1
sroes
  • 14,663
  • 1
  • 53
  • 72