changing date/time string format javascript [duplicate] - javascript

This question already has answers here:
change date format in javascript
(3 answers)
Format date to MM/dd/yyyy in JavaScript [duplicate]
(3 answers)
How to convert string to Date object?
(3 answers)
How do I format a date in JavaScript?
(68 answers)
Closed 4 years ago.
I know there are many functions in javascript that changes the date format, but I want to change the format of the string.
How can I change
2018-05-10T21:12:08Z
to
2018-05-10 9:12:08 AM
The date function doesn't work since it's not a date type.

You can use moment library to do all kind of date/time operations.
var dt = moment('2018-05-10T21:12:08Z');
console.log(dt.format('YYYY-MM-DD h:mm:ss A'));

Related

Convert string(Date(1646764200000+0530)) to date in the format(dd-mm-yyyy) using javascript [duplicate]

This question already has answers here:
Parsing a Auto-Generated .NET Date Object with Javascript/JQuery
(2 answers)
How do I format a date in JavaScript?
(68 answers)
Ignore timezone offset while converting date - javascript
(2 answers)
Closed 12 months ago.
I'm Trying to convert the below string to date in the format(dd-mm-yyyy)
let dob = /Date(1646764200000+0530)/
The above value of Date is given in string,
How to convert it to date using JavaScript,
Tried a lot of methods, but it shows an error as invalid date.?
Converting to the DD-MM-YYYY requires formatting.
Here is one way to extract the date portion using the slice() method then formatting the output to your desired format. This assumes that the input date is always in the same form and length.
let dob = /Date(1646764200000+0530)/;
let date = new Date(+(""+dob).slice(6,19)).toLocaleString('en-GB',{year:"numeric",day:"2-digit",month:"2-digit"}).split("/").join("-");
console.log(date)

How to convert javascript date object ( since Unix epoch ) to date in RFC 3339? [duplicate]

This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Closed 2 years ago.
I want to convert the JavaScript date object
let date = Date.now();
to date in RFC 3339 format, so it would return like this:
2020-05-21T08:01:48+00:00
How can I convert it? Get Help! Thank you!~
Try toISOString.
new Date('2020-05-21 08:01:48').toISOString()

Does Javascript not have built in support for formatting date objects? [duplicate]

This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Where can I find documentation on formatting a date in JavaScript?
(39 answers)
Closed 5 years ago.
Does Javascript not have any built in support for formatting dates? I have a date object, and I want to format it to a format of my choice e.g. the date that I want to convert is '2017-12-22'. Is there not any function that I could use
something like var newFormattedDate = new Date('2017-12-22', 'mm/dd/yyyy')
so that the output is 22/12/2017
Javascript doesn't have support to give format to date. You can use moment.js.
Alternatively, you can use string#replace.
console.log('2017-12-22'.replace(/(....)-(..)-(..)/g,'$3/$2/$1'));

current date time to dd-mon-yyyy hh:mm:ss [duplicate]

This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Where can I find documentation on formatting a date in JavaScript?
(39 answers)
Format JavaScript date as yyyy-mm-dd
(50 answers)
Javascript format date / time [duplicate]
(5 answers)
Get String in YYYYMMDD format from JS date object?
(53 answers)
Closed 5 years ago.
In javascript I need to change the current date in the following format?I googled a lot but I didnt find the exact result.
I'm expecting the current date to format is 22-Sep-2017 13:37:02
Thanks in Advance
var ele = document.getElementsByTagName('h3')[0];
setInterval(function(){
var date =new moment().format('DD-MMM-YYYY hh:mm:ss');
ele.innerHTML = date;}
,1000);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js"></script>
<h3></h3>
Use momentjs and format your date according to your need.

convert Javascript timestamp into UTC format [duplicate]

This question already has answers here:
How do I get a UTC Timestamp in JavaScript?
(16 answers)
Closed 7 years ago.
For example if you receive a timestamp in Javascript:
1433454951000
How would you create a function to convert the timestamp into UTC like:
2015/6/4 GMT+7
var d1 = new Date("UNIX TIME STAMP HERE");
d1.toUTCString()
Originally asked here:
How do I get a UTC Timestamp in JavaScript?

Categories