Date syntax string in `dd-M-yyyy` format

I need to create a new date from a string in the format: dd-M-yyyy

Example:

 var dateStr = '16-Sep-2012'; var date = new Date(dateStr); 

However, IE is not very happy with this and considers date to be NaN . Anyone recommend me or give me a reliable parser for this? 10x for your help, BR

+4
source share
1 answer

Use the Date.parse function, and then call the new Date function for this variable. See a live example here .

 var date = Date.parse('16-Sep-2012'); var formatted_date = new Date(date); 

Using the jQuery globalization plugin , you can parse dates using Globalizaiton.parseDate. The plugin adds support for IE.

+5
source

Source: https://habr.com/ru/post/1442823/


All Articles