Parsing Date Strings in dd.mm.yyyy Format
Parsing date strings in a specific format can be a frequent task in JavaScript. Specifically, let's focus on handling dates in the 'dd.mm.yyyy' format.
To achieve this, we can use the powerful 'Date' object in combination with the 'String.split' method. Here's how:
var strDate = "03.09.1979"; // Input date string // Split the string into its individual components: day, month, year var dateParts = strDate.split("."); // Create a new Date object using the parsed components var date = new Date(dateParts[2], (dateParts[1] - 1), dateParts[0]);
In this code:
Refer to the Mozilla Core JavaScript Reference for the 'Date' object and 'String.split' method for further documentation. This technique provides a robust and efficient way to handle date strings in the 'dd.mm.yyyy' format in JavaScript.
The above is the detailed content of How to Parse Date Strings in \'dd.mm.yyyy\' format in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!