Anyone can help me out with the date format?
I have tried new Date(NumberValue)
but returning Invalid Date
MockServer:
"NumberValue": "2.018081E7"
Formatter:
if(ValueType === "D"){
return parseFloat(NumberValue);
Anyone can help me out with the date format?
I have tried new Date(NumberValue)
but returning Invalid Date
MockServer:
"NumberValue": "2.018081E7"
Formatter:
if(ValueType === "D"){
return parseFloat(NumberValue);
You could use a regex to split your date string into year, month, day, which you can then pass to new Date()
const s = '20180810'
const rx = /(\d{4})(\d{2})(\d{2})/
let [_, Y, M, D] = s.match(rx)
console.log(new Date(Y, M - 1 , D)) // month is zero indexed
Edit based on comment:
If you can use destructuring — match()
just returns an array so you can use indexes for the same effect:
var s = '20180810'
var rx = /(\d{4})(\d{2})(\d{2})/
var m = s.match(rx)
console.log(new Date(m[1], m[2] - 1, m[3])) // month is zero indexed
You could achieve use moment.js
var val = parseFloat(2.018081E7);
var date = moment(val,'YYYYMMDD').format('DD MMM YYYY');
console.log(date)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>