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`;
Related
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
This question already has answers here:
how to parse a "dd/mm/yyyy" or "dd-mm-yyyy" or "dd-mmm-yyyy" formatted date string using JavaScript or jQuery [duplicate]
(5 answers)
Convert dd-mm-yyyy string to date
(15 answers)
How do I format a date in JavaScript?
(68 answers)
Closed 2 years ago.
I have a date in string format - '25-03-2020' (dd-mm-yyyy). I want to convert it into string format '25 Mar' and display on Frontend.
How can I achieve this using Javascript?
This question already has answers here:
Javascript Date toString convert and format to local time
(3 answers)
Closed 3 years ago.
I would like to get date format like "20/06/2019 13:20:04.8517209" in Javascript
Try this:
d = new Date()
date = d.toLocaleString() + "." +d.getMilliseconds()
output: "20/06/2019, 13:22:03.517"
For cleaner version try to use moment js: https://momentjs.com/
moment(d).format('YYYY-MM-DDTHH:mm:ss.SSSSSSS')
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);
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 ?