Questions tagged [javascript-date]

7 questions
2
votes
1 answer

Creating a date object from a date string is one day older

I have a function where I convert a date string or a datetime string into a date object with time set to 00:00:00 - basically truncating the time. /** * @param dateString - can either be 2023-07-13 or 2023-07-13 03:03:03 */ const removeTime =…
dokgu
  • 4,957
  • 3
  • 39
  • 77
1
vote
3 answers

JavaScript convert date format to "YYYY-MM-DD"

I have a JavaScript string date: js code: const lastDayDate = new Date(selectedDate.getFullYear(), selectedDate.getMonth() + 1, 0); const options = { year: 'numeric', month: '2-digit', day: '2-digit' }; const formattedDate =…
William
  • 3,724
  • 9
  • 43
  • 76
1
vote
0 answers

date-fns: How to format dates for multiple languages?

I'm using date-fns in my React web app, and support multiple languages (English, French, and Spanish). I want to display the date in a way that makes sense to users of any of these three languages, and right now I do it like this: import en from…
gkeenley
  • 6,088
  • 8
  • 54
  • 129
0
votes
0 answers

Change of time zone after using setFullYear / setUTCFullYear

I was experimenting with javascript dates; and as a part of it, I wrote the following code in firefox console: var test = new Date(); for (var i = test.getFullYear(); i >= 1; i--) { test.setUTCFullYear(i, 0, 1); console.log(test); } This…
Muntasir
  • 798
  • 1
  • 14
  • 24
0
votes
1 answer

Convert nanoseconds timestamp to JavaScript Date()

I have a log with timestamps like, for example, 1686184163560519943. www.unixtimestamp.com says they're nanoseconds. I want to convert these to Date() and then to toLocaleTimeString(). Date() does not like this input and throws Invalid Date. The…
0
votes
0 answers

How to change to the next object in an array in javascript based on the date changing - how to change to the next word of the day

I have very little experience with coding and I've never asked a question on here so please bear with me. I am trying to make a "word of the day" generator with html, css, and javascript specifically (please no other languages if possible), for my…
0
votes
0 answers

Is there a way to convert Moment Date to Javascript Date object along with locale?

I have the following function, which receives the date string and then checks if it is v alid moment date and then converts it to a JavaScript Date object. const dateFromString = (value, locale) => { if (typeof value === 'string') { const…
tRuEsAtM
  • 3,517
  • 6
  • 43
  • 83