Being scouring the net for a Javascript date version of the following: Saturday 5th November, 2016 I've tried looking at day and month arrays... Im kinda stumped. This particular date format I got from the php date format of: date("l jS F, Y"). Is there a Javascript version of this - (complete with date suffix)? any tips would be great. cheers.
Asked
Active
Viewed 61 times
0
-
3when in doubt defer to moment.js to simplify date tasks and formatting – charlietfl Nov 13 '16 at 02:32
-
Check out the [display docs](http://momentjs.com/docs/#/displaying/) for moment.js – Ben Nov 13 '16 at 02:34
-
[Where can I find documentation on formatting a date in JavaScript?](https://stackoverflow.com/questions/1056728/where-can-i-find-documentation-on-formatting-a-date-in-javascript) – Jonathan Lonowski Nov 13 '16 at 03:31
2 Answers
0
the closest format, try this
var d=new Date;
var str=d.toDateString();
console.log(str);
it will output like "Sun Nov 13 2016"

Liang
- 507
- 2
- 9
0
There isn't any JS native implementations to parse / display the format you mentioned
However, you could format this date string using momentjs. Here is an example on how you could do parse.
You could check more details on MomentJs Docs
let date = "Saturday 5th November, 2016";
let formattedDate = moment(date, "dddd Do MMMM, YYYY");
let jsDate = formattedDate.toDate();
console.log(jsDate.toString());
//Convert JS Date to formatted
let jsDateObj = moment().format("dddd Do MMMM, YYYY");
console.log(jsDateObj);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.16.0/moment.min.js"></script>

Sreekanth
- 3,110
- 10
- 22