How convert localString date to new Date? [duplicate] - javascript

This question already has answers here:
Parsing a string to a date in JavaScript
(35 answers)
Closed 4 years ago.
I have local string date: 12/3/2018, 12:00:00 AM.
How to convert it to Date()?

Add a Z at the end of the localString
var a=new Date('12/3/2018, 12:00:00Z');
console.log(a);

Related

Convert Date without "T" and "Z" to Date with T-Z Format [duplicate]

This question already has answers here:
Parsing a string to a date in JavaScript
(35 answers)
How do I format a date in JavaScript?
(68 answers)
Closed 1 year ago.
I have a JSON file with date format in the form of
2021-09-21 15:37:29.590 +03:00.
How can we convert it to a Date in a T-Z Format ?
You can pass it into the Date constructor and call toISOString.
const convert = (dateString) => new Date(dateString).toISOString();
console.log(convert('2021-09-21 15:37:29.590 +03:00')); // 2021-09-21T12:37:29.590Z

How do I convert a datetime to this? [duplicate]

This question already has answers here:
Parsing a string to a date in JavaScript
(35 answers)
Where can I find documentation on formatting a date in JavaScript?
(39 answers)
How do I format a date in JavaScript?
(68 answers)
Convert date to another timezone in JavaScript
(34 answers)
Why does Date.parse give incorrect results?
(11 answers)
Closed 1 year ago.
In Javascript, I have a datetime string that looks like:
2021-03-12 19:52:09
How do I convert it so it appears in this format?
03/12 12:34pm PST
Ideally I would like to do so without external libraries.
You could format it manually like this:
now = Date.now();
pst = new Date(now-(8*60*60*1000)); //-8 hours for pst
pst_str = `${pst.getMonth()}/${pst.getDate()} ${pst.getHours()%12}:${pst.getMinutes()}${pst.getHours()>=12?'pm':'am'} PST`;

convert javascript string to date object [duplicate]

This question already has answers here:
Parsing a string to a date in JavaScript
(35 answers)
Why does Date.parse give incorrect results?
(11 answers)
Closed 4 years ago.
I am getting an error when I try to format the following date.
var d = new Date('Jan 01 2019 12:00AM');
I am getting Invalid Date
You need to remove AM from your line new date.
var d = new Date('Jan 01 2019 12:00');

How can I convert a string to Date object in javascript? [duplicate]

This question already has answers here:
Convert dd-mm-yyyy string to date
(15 answers)
Parsing a string to a date in JavaScript
(35 answers)
Closed 4 years ago.
I have something like
var endDate = $('#endDateHistory').val();
and it returns as "12.04.2018" (string) . How can I change it into Date object so that I can use it in DatePicker ?

JSON date with Timezone offset not converting to JavaScript Date correctly [duplicate]

This question already has answers here:
How to parse JSON to receive a Date object in JavaScript?
(17 answers)
Parsing Date from webservice
(2 answers)
Closed 9 years ago.
I've got this following string from JSON API:
"Date": "\/Date(1381446000000+0100)\/",
which should be:
2013-10-11 00:00:00
but instead I get this:
2013-10-10T23:00:00.000Z
My code:
new Date(parseFloat(oldDate.replace("/Date(", "").replace(")/", "")));
Try This :
var date = "/Date(1381446000000+0100)/";
var d = new Date(parseFloat(date.replace("/Date(", "").replace(")/", "")));

Categories

Resources