A macro can't do that, just an UltraEdit script.
It is not possible to add a script to toolbar as symbol. But you can add the script with
Scripting - Script List to the list of scripts and assign a hotkey or chord for fast execution. Or the script is executed by a click on the script in menu
Scripting or by a double click on the script in the
Script List opened via
View - Views/Lists - Script List if currently closed completely.
Code: Select all
if (UltraEdit.document.length > 0) // Is any file opened?
{
// Is a string selected in active file?
if (UltraEdit.activeDocument.isSel())
{
var sSecondsSinceEpoch = UltraEdit.activeDocument.selection;
var nSecondsSinceEpoch = parseInt(sSecondsSinceEpoch,10);
// Is the selected string really a number?
if (nSecondsSinceEpoch != NaN)
{
// Create a date object with milliseconds value since epoch.
oDateTime = new Date(nSecondsSinceEpoch*1000);
// Get full year (with century) in local time as string.
var sYear = oDateTime.getFullYear().toString(10);
// Get month with leading zero in local time as string.
var nMonth = oDateTime.getMonth() + 1;
var sMonth = (nMonth < 10) ? "0" : "";
sMonth += nMonth.toString(10);
// Get day with leading zero in local time as string.
var nDay = oDateTime.getDate();
var sDay = (nDay < 10) ? "0" : "";
sDay += nDay.toString(10);
// Get hour with leading zero in local time as string.
var nHour = oDateTime.getHours();
var sHour = (nHour < 10) ? "0" : "";
sHour += nHour.toString(10);
// Get minute with leading zero in local time as string.
var nMinute = oDateTime.getMinutes();
var sMinute = (nMinute < 10) ? "0" : "";
sMinute += nMinute.toString(10);
// Get second with leading zero in local time as string.
var nSecond = oDateTime.getSeconds();
var sSecond = (nSecond < 10) ? "0" : "";
sSecond += nSecond.toString(10);
// Build complete time string in format dd.mm.yyyy hh:mm:ss.
var sDateTime = sDay + "." + sMonth + "." + sYear + " " +
sHour + ":" + sMinute + ":" + sSecond;
// Overwrite the selected text in file with this time string.
UltraEdit.activeDocument.write(sDateTime);
}
}
}
Please read the comments in this script and adapt the output format to your requirements.
See also the documentation for
Date object of JavaScript core. As you can read there, there are also UTC time functions.
To use a different time zone simply add/subtract right offset in milliseconds on line:
Code: Select all
oDateTime = new Date(nSecondsSinceEpoch*1000);
See also similar topic
Convert epoch time stamps to UTC/local time.