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 2 years ago.
Is there a way to convert this date input 01 Nov 2020, 9:55pm +10:00 to a timestamp like this 2020-11-01T11:55:00Z?
use new Date("01 Nov 2020, 9:55 pm +10:00").toISOString()
NOTE: make sure that 9:55 and PM are separated
const date = new Date("01 Nov 2020, 9:55 pm +10:00").toISOString()
console.log(date)
you can use moment lib.
sample:
const moment = require("moment");
const inputDate = "01 Nov 2020, 9:55pm +10:00";
const formatedDate = moment(inputDate, "DD MMM YYYY, HH:mmA ZZ");
Related
This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Closed last month.
I have data available in ISO format which is 2021-06-01T00:00:00.000Z. I want to convert it into 1st June 2021 format.
Below is what I did
const dat = 2021-06-06T00:00:00.000Z;
const d = new Date(dat);
console.log(d.toDateString());result
I am getting this Tue Jun 01 2021. How can I format this into desired format?
You can use moment.js libary for date conversion.
let yourDate = "2021-06-06T00:00:00.000Z";
let convertedDate = moment(yourDate).format("Do MMMM YYYY");
console.log("Result (6th June 2021) ==>>", convertedDate)
<script type = "text/JavaScript" src = "https://MomentJS.com/downloads/moment.js"></script>
This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Closed 4 years ago.
I have a string date like this:
2018-08-26T00:00:00.000Z
Is there a way that I can format it so it looks similar to this format?
Fri, 24 Aug 2018 09:30:00 GMT
E, d MMM yyyy HH:mm:ss zzz
Simply construct a Date object, and then you can use Date.prototype.toUTCString to format the string in the GMT format:
var date = new Date('2018-08-26T00:00:00.000Z');
console.log(date.toUTCString());
This question already has answers here:
Where can I find documentation on formatting a date in JavaScript?
(39 answers)
Closed 4 years ago.
How to get this date format?
Apr 22, 2018 12:44:58 PM
I've tried this code (new Date()).toUTCString() but the result is like
Sun, 22 Apr 2018 10:45:19 GMT
Easiest way is to leverage MomentJS - you can then use:
moment().format('MMM DD, YYYY hh:mm:ss A')
This question already has answers here:
“Deprecation warning: moment construction falls back to js Date” when trying to convert RFC2822 date in moment.js
(7 answers)
Closed 6 years ago.
I have a date string like this: "Mon Jul 18 2016 21:35:14 GMT+00:00" and would like to use this in moment to format it to "MM-DD-YYYY", it does that but throws a warning pointing back to this issue https://github.com/moment/moment/issues/1407
Is there a way that I can convert the above to a date object and then use it in moment for formatting something like:
moment(Mon Jul 18 2016 21:35:14 GMT+00:00).format('MM-DD-YYYY');
You should include the string and the format within the moment call:
var date_as_string = "Mon Jul 18 2016 21:35:14 GMT+00:00";
var current_format = "ddd MMM DD yyyy HH:mm:ss Z";
moment(date_as_string, current_format).format('MM-DD-YYYY');
You are telling the function what format your string is in so that it can parse it correctly.
This question already has answers here:
Convert iso timestamp to date format with Javascript?
(4 answers)
Closed 7 years ago.
I have date in ISO-format like:
2016-02-17T16:40:30
How can I convert it to a human-readable date, for example:
17 Feb 2016 16:40
First of all, you need to create a date using your original date string.
var d = new Date('2016-02-17T16:40:30');
And then you can use this to fetch a readable date format:
d.toDateString();
Will return:
Wed Feb 17 2016