Hello Apigee Community,
What's the best way to convert a JSON variable from EPOCH to DateTime?
Can this be done via JavaScript Policy?
If so, do you have an example?
Thank you!
Solved! Go to Solution.
This ended up working for me:
var dateTime = JSON.parse(context.getVariable('PaymentDateTime')); var PaymentDateTime = new Date(dateTime * 1000).toISOString("yyyy'-'MM'-'dd HH':'mm':'ss'Z'"); context.setVariable("PaymentDateTime", PaymentDateTime);
Not sure what you mean by json variable but you can use below js snippet to convert to datetime.
var timestamp = context.getVariable("system.timestamp");
var mydate = new Date(timestamp);
var isoDate = mydate.toString('dddd MMM yyyy h:mm:ss');
context.setVariable("isoDate", isoDate);
If I want to replace "PaymentDateTime" to DateTime how would I do this?
Also, if you have any inputs on how I can convert the "PaymentAmount" to the "70.00" that would be helpful as well.
Thank you!
{ "PaymentAmount": "7000", "PaymentDateTime": "1523971980" }
This ended up working for me:
var dateTime = JSON.parse(context.getVariable('PaymentDateTime')); var PaymentDateTime = new Date(dateTime * 1000).toISOString("yyyy'-'MM'-'dd HH':'mm':'ss'Z'"); context.setVariable("PaymentDateTime", PaymentDateTime);
Glad you are able to resolve.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |