I got this string from an api After looking at it I realized it was a dat/time
20220112201146
I then decoded it by hand to be
2022(Y)01(M)12(D)20(H)11(M)46(S)
How would I slice everything up to be Y:M:D:H:M:S? Example:
2022:01:12:20:11:46
And then add 80 mins to it?
Date
constructor (andDate.parse
, which works the same way) is strongly discouraged due to browser differences and inconsistencies.” — From the documentation. The correct solution will look something likeconst { year, month, day, hour, minute, second } = theDateString.match(/(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})(?<hour>\d{2})(?<minute>\d{2})(?<second>\d{2})/).groups, result = new Date(year, month - 1, day, hour, minute, second);
.result.setMinutes(result.getMinutes() + 80);
andconst stringResult = `${String(result.getFullYear()).padStart(4, "0")}:${String(result.getMonth() + 1).padStart(2, "0")}:${String(result.getDate()).padStart(2, "0")}:${String(result.getHours()).padStart(2, "0")}:${String(result.getMinutes()).padStart(2, "0")}:${String(result.getSeconds()).padStart(2, "0")}`;
for the format.let [C,Y,M,D,H,m,s] = '20220112201146'.match(/\d\d/g); new Date(C+Y, M-1, D, H, m, s)
. That simple.new Date().toLocaleString('en-CA').replace(/\D/g, '')
.