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

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.

Related

How to get a week ago as UTC timestamp in JavaScript? [duplicate]

This question already has answers here:
how do I subtract one week from this date in jquery?
(4 answers)
How do I output an ISO 8601 formatted string in JavaScript?
(16 answers)
Closed 6 months ago.
How can I get a UTC timestamp of a week ago in ISO 8601 format (i.e., YYYY-MM-DDTHH:MM:SSZ) using JavaScript?
I don't want to use any libraries.
Using standard Date functions:
const d = new Date();
d.setDate(d.getDate() - 7);
console.log(d.toISOString());

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()

changing date/time string format javascript [duplicate]

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'));

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