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

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

Related

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

How to convert a number to a date in JavaScript [duplicate]

This question already has answers here:
Convert UTC Epoch to local date
(16 answers)
Closed 4 years ago.
I have a number, "1546108200", in epoch format.
I want to convert into a date format, like "Sunday, December 30, 2018 12:00:00 AM".
How can I do that?
You can use this:
var date = new Date(1546108200 * 1000);
console.log(date.toUTCString())

Subtract one day from a particular date using MomentJs [duplicate]

This question already has answers here:
Moment JS - how to subtract 7 days from current date?
(6 answers)
Format date and Subtract days using Moment.js
(7 answers)
Closed 4 years ago.
I get the second week of 2018 like this using moment.js
var date =moment([2018]).isoWeek(2).startOf('isoWeek').format('DD-MM-YYYY');
I need to get the date previous to the this date; i.e. the date previous to
08-01-2018
Use moment substract method:
.subtract(1, 'days');

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