(epochtime).mp4 to yyyymmdd-hhmmss.mp4

Advanced Renamer forum
#1 : 11/05-22 15:51
Herb
Herb
Posts: 1
Hi. I have reviewed several threads on this help forum and one of them comes close. I modified it and it got me the format I wanted but the dates were totally not correct as doublechecked by pasting the file name into (https://www.epochconverter.com/) Another solution thread threw access violation errors. I know a few programming languages and database languages but not javascript but I was able to figure out how to make a mod to the one that was pretty close (as mentioned above) but I'm still stuck. Would someone be able to help? here's a small sample of what I have....


1651876519999.mp4
GMT: Friday, May 6, 2022 10:35:19.999 PM
Your time zone: Friday, May 6, 2022 5:35:19.999 PM GMT-05:00 DST
Relative: 5 days ago

1651967063944.mp4
GMT: Saturday, May 7, 2022 11:44:23.944 PM
Your time zone: Saturday, May 7, 2022 6:44:23.944 PM GMT-05:00 DST
Relative: 4 days ago

1652057273497.mp4
GMT: Monday, May 9, 2022 12:47:53.497 AM
Your time zone: Sunday, May 8, 2022 7:47:53.497 PM GMT-05:00 DST
Relative: 3 days ago

1652145227476.mp4
GMT: Tuesday, May 10, 2022 1:13:47.476 AM
Your time zone: Monday, May 9, 2022 8:13:47.476 PM GMT-05:00 DST
Relative: 2 days ago

1652231545048.mp4
GMT: Wednesday, May 11, 2022 1:12:25.048 AM
Your time zone: Tuesday, May 10, 2022 8:12:25.048 PM GMT-05:00 DST
Relative: 13 hours ago

1652275905467.mp4
GMT: Wednesday, May 11, 2022 1:31:45.467 PM
Your time zone: Wednesday, May 11, 2022 8:31:45.467 AM GMT-05:00 DST
Relative: 19 minutes ago


11/05-22 15:51 - edited 11/05-22 15:53
#2 : 11/05-22 20:46
David Lee
David Lee
Posts: 935
The following should convert the UNIX epoch into the desired format in the timezone that your computer is using :

date = new Date(+item.newBasename);
return date.getFullYear().toString()
+ ("0" + (date.getMonth() + 1)).slice(-2)
+ ("0" + date.getDate()).slice(-2)
+ "-" + ("0" + date.getHours()).slice(-2)
+ ("0" + date.getMinutes()).slice(-2)
+ ("0" + date.getSeconds()).slice(-2);

If you need to output the date/time corresponding to an arbitrary timezone then just add the timezone offset in milliseconds to the timestamp before converting to a date then extract the components as UTC.

For UTC-5 :

timeZone = -5 * 3600000;
date = new Date(+item.newBasename + timeZone);
return date.getFullYear().toString()
+ ("0" + (date.getUTCMonth() + 1)).slice(-2)
+ ("0" + date.getUTCDate()).slice(-2)
+ "-" + ("0" + date.getUTCHours()).slice(-2)
+ ("0" + date.getUTCMinutes()).slice(-2)
+ ("0" + date.getUTCSeconds()).slice(-2);


11/05-22 20:46 - edited 12/05-22 01:17