Your data. Anywhere you go.

New Relic for iOS or Android

Download on the App Store    Android App on Google play

New Relic Insights App for iOS

Download on the App Store

Learn more

Close icon

Format Date to RFC2822 format




I’m trying to create an Duo API Test on synthetics and the header needs a Date that is converted on RFC2822 format.

Thu, 18 Jul 2019 03:08:51 -0000

I tried using
var utcDate = new Date().toUTCString();

but I’m having this as result
Thu, 18 Jul 2019 03:08:51 GMT

How do i get or convert the 'GMT' into '-0000'

My temporary solution as of now is this
var subStrDuodate = utcDate.toString().substring(0,25) + " -0000";

Thanks in advance!


Hi, @Reynaldo.Udasco: The Synthetics runtime supports the moment module, so you can do this:

var moment = require('moment');

var DATE_RFC2822 = "ddd, DD MMM YYYY HH:mm:ss [GMT]";