can someone help me solve this problem. In my textfield I have a value of January 01,1970 and I want it to change to 1970-01-01(year-month-day). How to do it in javascript?
Asked
Active
Viewed 241 times
-2
-
3What you have tried so far ? – Code Maniac Feb 17 '19 at 12:33
-
1Read about `momentjs`, `new Date('January 01,1970')` `<-` Not reliable! – Ele Feb 17 '19 at 12:34
-
@CodeManiac I have tried toLocaleString but I got 'not a function' error on my console. – Greybox Feb 17 '19 at 12:40
-
1Go over there, it's already resolved : https://stackoverflow.com/questions/23593052/format-javascript-date-to-yyyy-mm-dd – soumare Feb 17 '19 at 12:41
-
2Possible duplicate of [Format JavaScript Date to yyyy-mm-dd](https://stackoverflow.com/questions/23593052/format-javascript-date-to-yyyy-mm-dd) – Nick Parsons Feb 17 '19 at 12:44
1 Answers
1
You can use momentJS
let date = `January 01,1970 `
console.log( moment(date).format('YYYY-MM-DD'))
<script src="https://rawgit.com/moment/moment/2.2.1/min/moment.min.js"></script>

Nasir Kamal
- 114
- 1
- 7

Code Maniac
- 37,143
- 5
- 39
- 60
-
1I have moment.js and I never know that it can help me until you answered my inquiry. Thanks – Greybox Feb 17 '19 at 13:03