I have an array of strings corresponding to Date objects. like this:
const timestamps = [
'2023-03-15T10:47:38.878Z',
'2023-03-15T10:46:51.375Z',
'2023-03-15T10:46:39.645Z',
'2023-03-15T10:47:19.072Z',
'2023-03-15T10:46:20.395Z'
]
var convertedTimestamps = [];
for (var time in timestamps) {
var timeAsDate = Date.parse(time);
console.log(time, timeAsDate);
convertedTimestamps.push(timeAsDate);
}
const min = Math.min(...convertedTimestamps);
They are Date objects parsed into strings for other purposes This can be any length really, this is just one instance of it. I want to find the oldest of the timestamps.
In the example above, these are the converted timestamps, and the min value is correct based on the numbers, but not the date objects. The top one is the one that is removed
946681200000
978303600000
980982000000
983401200000
986076000000
min: 946681200000
'2023-03-15T10:47:38.878Z'
It might just be a math problem, but the way i understand it, a string parsed like this returns an int representing how much time has passed since 1970 etc, and so the oldest should be closest to that time should it not? this min value is in fact the most recent of the timestamps. When i try the max value it is not correct either.