Edit: See wysocki's reply below for an improved version
function OnGetNewName(getNewNameData)
{
var epochTime = parseInt(getNewNameData.item.name_stem_m);
var date = new Date(epochTime);
var y = zeroPad(date.getFullYear(), 4);
var m = zeroPad(date.getMonth(), 2); // BUG: See wysocki's reply below
var d = zeroPad(date.getDay(), 2); // BUG: See wysocki's reply below
var n = y + "-" + m + "-" + d + getNewNameData.item.ext_m;
return n;
}
function zeroPad( number, digits )
{
var numStr = number.toString()
var width = digits - numStr.length;
while (width > 0)
{
numStr = "0" + numStr;
width = width - 1;
}
return numStr; // always return a string
}
Great! I also needed this to convert the epoch time from Arlo security cameras. And I've modified the script here to also include the time. PLUS, I fixed a couple of errors in the script by adding 1 to the month number and using getDate instead of getDay (day of the month instead of day of the week)!
Can't believe I got to correct Leo's work!!!
function OnGetNewName(getNewNameData)
{
var epochTime = parseInt(getNewNameData.item.name_stem_m);
var date = new Date(epochTime);
var y = zeroPad(date.getFullYear(), 4);
var m = zeroPad(date.getMonth() + 1, 2);
var d = zeroPad(date.getDate(), 2);
var h = zeroPad(date.getHours(), 2);
var mi = zeroPad(date.getMinutes(), 2);
var s = zeroPad(date.getSeconds(), 2);
var n = y + "-" + m + "-" + d + " " + h + "." + mi + "." + s + getNewNameData.item.ext_m;
return n;
}
function zeroPad( number, digits )
{
var numStr = number.toString()
var width = digits - numStr.length;
while (width > 0)
{
numStr = "0" + numStr;
width = width - 1;
}
return numStr; // always return a string
}