This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Closed 1 year ago.
I have a .NET application that returns the date in this format: 2021-12-29T15:04:09.0129998.
I need a Javascript form to format to "December 29, 2021".
All the examples I've found so far use "new date " to exemplify, like this example here:
const currentDate = new Date();
console.log(currentDate.toLocaleDateString('de-DE'));
that creates a date in a different format from mine and then it works. In my case it doesn't work.
new Date().toDateString("de-DE").substring(3)
This question already has answers here:
JavaScript - get the first day of the week from current date
(20 answers)
Closed 4 years ago.
$gte: ISODate("2010-04-29T00:00:00.000Z"),$lt: ISODate("2010-05-01T00:00:00.000Z")
You may get the day of the week by calling .getDay() on the date object. Once you have the day of the week, rest are arithmetic operations.
To convert Date to ISODateFormat you can use toISOString
var dateForCalculation = new Date();
var prevSunday = new Date(dateForCalculation.setDate(dateForCalculation.getDate()-dateForCalculation.getDay())).toISOString();
var nextSunday = new Date(dateForCalculation.setDate(dateForCalculation.getDate()+7)).toISOString();
console.log(prevSunday);
console.log(nextSunday);
This question already has answers here:
Where can I find documentation on formatting a date in JavaScript?
(39 answers)
Closed 5 years ago.
I got this JS code:
var d = new Date();
d.setDate(d.getDate() + (1 + 7 - d.getDay()) % 7);
document.write(d);
and I want JS to display it in dd/mm/yyyy. How can I do that?
Thank you,
Till
Try this link to W3 Schools date formatting:
https://www.w3schools.com/js/js_date_formats.asp
and date methods:
https://www.w3schools.com/js/js_date_methods.asp
and check out this previous S/O answer:
How to convert a full date to a short date in javascript?
This question already has answers here:
Javascript Date.UTC() function is off by a month?
(4 answers)
Closed 5 years ago.
I get dates from server as a list, for example, [2017,8,24,9,0]. When I parse and localize them in momentjs, all the dates are one month ahead: instead of August, I get September. In case of [2017,8,31,9,0], I get invalid date.I think it is because September is not 31 days.
My question is how to parse dates such as [2017,8,24,9,0], [2017,8,29,20,0], and [2017,8,31,9,0] into D.MMM [kl.] H:mm format?
I understand that JavaScript date is zero-indexed while java date isn't. I have used momentjs subtract() method, but [2017,8,31,9,0] is still invalid date.
That's a javascript issue. But is not a bug. In js dates, months are zero based. It is, 0 = january, 1 = february, etc. To solve this you can subtract the month by 1.
var myServerDate = [2017,8,24,9,0];
myServerDate[1] = myServerDate[1] -1;
Then you can proceed with the parsing process.
This question already has answers here:
convert iso date to milliseconds in javascript
(10 answers)
Closed 7 years ago.
I have a date as a String like : 2015-12 for december 2015.
I would like to convert this date to get this date in milliseconds in javascript. (From the first day of the month)
How can i do it ?
Try using the Date object (new Date()).
You could do :
YourDate + "-01"
And then try to convert to a date
d = new Date(YourDate)
And finaly :
d.getMilliseconds()