Sign In Register

How can we help you today?

Start a new topic

Creating Time Stamps for Challenges in Cloud Code

Here's a code snippet to help you quickly create time stamps for your Challenge requests.  This uses UTC time because challenges work on UTC time.


       

//Current local time
var now = new Date();

//A day in the future of UTC time
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);

//An hour in the future of UTC time
var inHour = new Date();
inHour.setSeconds(inHour.getHours() + 1);

//One minute in the future of UTC time
var inOneMin = new Date();
inOneMin.setMinutes(inOneMin.getMinutes() + 1);

//Turn to ISO string format
var nowISO = now.toISOString();
var tomorrowISO = tomorrow.toISOString();
var inHourISO = inHour.toISOString();
var inOneMinISO = inOneMin.toISOString();

//Cull the string and add Z at the end to suffice Challenge time format
//Result will look like: "YYYY-MM-DDTHH:MMZ" for example: "2017-06-21T11:18Z" 
nowCorrectFormat  = nowISO.substr(0,16) + "Z";
tomorrowCorrectFormat  = tomorrowISO.substr(0,16) + "Z";
inHourCorrectFormat  = inHourISO.substr(0,16) + "Z";
inOneMinCorrectFormat  = inOneMinISO.substr(0,16) + "Z";

     

Cheers,

Omar  

Login to post a comment