Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Time conversion in javascript policy

Hi everyone,

I tried to get epoch time in javascript, and here is what I did:

var begin_date = context.getVariable("date_begin"); //20171001

var begin_year = begin_date[0] + begin_date[1] + begin_date[2] + begin_date[3];
var begin_month = begin_date[4] + begin_date[5];
var begin_day = begin_date[6] + begin_date[7];


var raw_begin_date = begin_month + '/' + begin_day + '/' + begin_year + " 00:00:00";
var converted_begin_date = new Date(raw_begin_date);
converted_begin_date = converted_begin_date.getTime();

context.setVariable("date_begin", converted_begin_date);
<br>

Using the code above, I ran it on browser's console and my node.js and I get is 1506790800000. But in edge, what I got is 1.506816E12

What should I do to fix this?

Regards,

Yoga

Solved Solved
1 6 1,734
2 ACCEPTED SOLUTIONS

HI @Yoga Prakoso

While assigning it to a flow variable, convert it to a String

context.setVariable("date_begin", converted_begin_date.toString());

That could fix the issue. Please try and let us know

View solution in original post

Not applicable

What calls my attention is that epocs are not equal.

Browser: 1506790800000

GMT: Saturday, 30th September de 2017 17:00:00

Not the value we wanted

Edge: 1506816000000 (equals 1.506816E12)

GMT: Sunday, 1st October de 2017 0:00:00

The right value!

In addition to @Sai Saran Vaidyanathan's answer, I suggest you to include timezone on your

raw_begin_date

View solution in original post

6 REPLIES 6