How can I convert the following date format below (Mon Nov 19 13:29:40 2012)
into:
dd/mm/yyyy
<html> <head> <script type="text/javascript"> function test(){ var d = Date() alert(d) } </script> </head> <body> <input onclick="test()" type="button" value="test" name="test"> </body> </html>
const d = new Date("2015/03/25"); The behavior of "DD-MM-YYYY" is also undefined. Some browsers will try to guess the format. Some will return NaN.
To convert dd/mm/yyyy string into a JavaScript Date object, we can pass the string straight into the Date constructor. const dateString = "10/23/2022"; const dateObject = new Date(dateString);
First, pick the cells that contain dates, then right-click and select Format Cells. Select Custom in the Number Tab, then type 'dd-mmm-yyyy' in the Type text box, then click okay. It will format the dates you specify.
Some JavaScript engines can parse that format directly, which makes the task pretty easy:
function convertDate(inputFormat) { function pad(s) { return (s < 10) ? '0' + s : s; } var d = new Date(inputFormat) return [pad(d.getDate()), pad(d.getMonth()+1), d.getFullYear()].join('/') } console.log(convertDate('Mon Nov 19 13:29:40 2012')) // => "19/11/2012"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With