Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a date object from a date-string which contains AM/PM?

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");
like image 805
Pawan Nogariya Avatar asked Dec 24 '11 12:12

Pawan Nogariya


People also ask

How can I get AM PM from date in moment?

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").

How do you write a date object?

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.

Is a Date object a string?

Here, year , day , time and date_time are strings, whereas now is a datetime object.


1 Answers

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/

like image 154
Šime Vidas Avatar answered Oct 25 '22 14:10

Šime Vidas