Link to home
Start Free TrialLog in
Avatar of Member_2_1242703
Member_2_1242703

asked on

Converting dates in JavaScript

I have this as a returned value from SQL to JavaScript

/Date(1486101600000)/

(In SQL it's 2017-01-30 00:00:00.000)

How do I convert this to 01-30-2017 in JavaScript?
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can use also moment.js  wich is a javascript library to manipulate dates and times more shortly. First you must include inside the head the following script
<script>https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/locale/af.js</script>

Open in new window

wich is the latest version.
Then write your code as the following code
var t = 1486101600000;
var formatted = moment(t).format("DD/MM/YYYY");
console.log(formatted);

Open in new window


the output console is... 03/02/2017