Is there any way to define a javascript date object with AM/PM value?
Something like this
var startDate = new Date("1900-1-1 8:20:00 PM");
To get am pm from the date time string using moment. js and JavaScript, we use the 'A' format code. console. log( moment("Mon 03-Jul-2022, 11:00 AM", "ddd DD-MMM-YYYY, hh:mm A").
You can create a Date object using the Date() constructor of java. util. Date constructor as shown in the following example. The object created using this constructor represents the current time.
Here, year , day , time and date_time are strings, whereas now is a datetime object.
This works:
new Date( '1 Jan 1900 8:20:00 PM' )
and is equivalent to
new Date( '1 Jan 1900 20:20:00' )
Live demo: http://jsfiddle.net/cVE2E/
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