0

Not looking for the environment-specific date methods like this for calculating these date fields, but how do you isolate them from a Unix timestamp such as now, which was 1650045773120? It is in milliseconds from Jan 1 1970 UTC, but I'm not sure how to do the conversion to isolate these values. If there are links to source code which already show the implementation, that would work too.

const start = new Date(0)
const now = Date.now()

This seems like it will be fairly complex, so wondering how JodaTime or the JavaScript Date implement this under the hood, and perhaps where the source code is. Unless you know how to do it directly.

Ole V.V.
  • 76,217
  • 14
  • 120
  • 142
Lance
  • 69,908
  • 82
  • 257
  • 454
  • Trying to learn from [this](https://stackoverflow.com/questions/35379513/convert-unix-time-to-month-number) and perhaps [this](https://gist.github.com/t3hk0d3/6186590), but looking for a somewhat optimal approach. – Lance Apr 15 '22 at 18:13
  • Was the Joda-Time or the java.time source code hard to find? – Ole V.V. Apr 17 '22 at 17:57

1 Answers1

-1

If you are trying to find difference between two different dates. Try This :

const today = new Date();  //that is currect time, if you want to use a date of     
// your choice then write new Date('mm-dd-yy')
const christmas = new Date('12/25/2022');
const timeDiff = Math.abs(christmas - today);
const daysDiff = Math.ceil(timeDiff /(1000*60*60*24));
const hoursDiff = Math.ceil(daysDiff * 24)
console.log(timeDiff + "miliseconds left")
console.log(daysDiff + "days left")
console.log(hoursDiff + "hours left")

And if you're trying to get the date month year of a particular date. Try this:

const today = new Date();  //that is currect time, if you want to use a date of your choice then write new Date('mm-dd-yy')

console.log(today.getDate(), today.getHours(), today.getFullYear(), today.getHours())
debugger
  • 328
  • 1
  • 8
  • 1
    I am asking how to do it without the date object. I think I found something relevant [here](https://github.com/v8/v8/blob/f6911f6be82f5ea1d9d095f594b717ea28e17588/src/date-delay.js). – Lance Apr 15 '22 at 18:23