#1 : 11/06-20 09:06 agus
Posts: 2
|
Hello
I just used AdvancedRenamer and i need to rename hour format in the part of the filename from UTC to GMT+7 For example : 1. Audio_meeting(1)_92345136_837462537844_2020-03-19_03-15-55.wav become Audio_meeting(1)_92345136_837462537844_2020-03-19_10-15-55.wav --> Changing hour from 03 (UTC format) to 10 (GMT+7 format) 2. Video_meeting(2)_92345188_837465457844_2020-03-19_04-15-55.wav become Video_meeting(2)_92345188_837465457844_2020-03-19_11-15-55.wav --> Changing hour from 04 (UTC format) to 11 (GMT+7 format) Thanks |
#2 : 11/06-20 14:28 David Lee
Posts: 1125
|
This is an interesting problem. For your two examples it would be a simple matter of adding 7 to the hours field. However we will run into trouble if this takes us past midnight, in which case the day will have to be incremented and possibly the month and year. If you are really unlucky you may even have to take account of a leap year!
Easiest solution is to use a Script. Extract the date and time using a regular expression and convert to a Unix epoch (ie milliseconds since midnight on 01/01/1970). Then add 7 hours (= 7 * 360000 milliseconds) and convert back to datetime format. Finally reassemble into the original format. Paste this code into a Script method: match = item.name.match(/^(.*_)(\d{4}-\d{2}-\d{2})_(\d{2})-(\d{2})-(\d{2})$/); epoch = Date.parse(match[2] + 'T' + match[3] + ':' + match[4] + ':' + match[5]); date = new Date(epoch + 7 * 3600000); return match[1] + date.getFullYear() + "-" + ("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); |
#3 : 11/06-20 15:51 agus
Posts: 2
|
Reply to #2:
Great. It works. Just slight modification on : date = new Date(epoch + (7* 3600000)); |
#4 : 13/06-20 09:42 David Lee
Posts: 1125
|
Reply to #3:
Your modification should be unnecessary since multiplication and division have a higher priority than addition and subtraction, so "*" is always evaluated before "+" in an expression, regardless of order. |