How would I go about converting following date:
Thu Feb 18 12:25:00 SGT 2016
into a format like '2016-02-18'?
I know,
- That, using a new Date(Date.parse('...')), with calls, will help me get it. But the problem being timezone part (SGT).
- I dont want to use any libraries out there.
What would be the effective way to go about this?
Any help is appreciated!
PS:
Ok, I have tried
new Date(Date.parse('Thu Feb 18 12:25:00 SGT 2016'))
but of-course, it is going to me 'invalid date' error.
Try this code no date parsing required. Please check on console for result.
I guess I should wait for you to post some code, but here's an example. It splits the string into parts, converts the month name to a number, then outputs the bits you want in the order you want. The slice on the month name is just in case you want to use the full month name, but maybe that's unnecessary:
That format date string (y/m/d) isn't consistent with any standard that I know of and likely will not be parsed by most browsers.
Why not just take the individual components of the date object and build a string from them?
I'll leave it to you to sort out the leading 0s on the day and month.