I am using below function. It is giving the output as Jul-7,-1988 for few users. It is working fine for all the users and giving correct result like 7-Jul-1988. Anyone knows how to fix this issue. I want the result to be in 07-Jul-1988 format for all the users. And why does it is changing into different format when I have specifically mention the format 'en-GB'.
function(data) {
var date = new Date(data);
return date.toLocaleDateString('en-GB', {
day: 'numeric', month: 'short', year: 'numeric'
}).replace(/ /g, '-')
}
I have found on this link - https://github.com/nodejs/node/issues/33761 that it behave differently. In my case also it could be the same issue ?
Update: Can I use the below approach to get the date in desired format or moment.js would be better idea?
function(data){
var months = ["JAN", "FEB", "MAR","APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
var current_datetime = new Date(data);
var formatted_date = current_datetime.getDate() + "-" + months[current_datetime.getMonth()] + "-" + current_datetime.getFullYear()
console.log(formatted_date)
}