December 16, 2024 at 10:12 am #30135
Keymaster
You can easily do this with a macro. First, create a macro similar to the one below (based on Patrick C’s work) and save it under a name like “WriteDateTime.jsee”.
Go to the Macros menu, select “Customize,” and navigate to the “My Macros” page. Make sure the macro you just saved appears in the “My Macros” list. If it doesn’t, click the “Add” button to include it. Once added, select the macro, click on “Runs at Events,” and then click the “Events” button. In the “Select Events” dialog, ensure that “File Opened” is enabled.
// Inspired by & resources
// https://www.emeditor.com/forums/topic/option-to-adjust-the-datetime-format-edit-insert-time-and-date/
// https://www.emeditor.com/forums/topic/insert-long-date/
// https://www.w3schools.com/jsref/jsref_tolocaledatestring.asp + jsref_getmonth.asp + jsref_getdate.asp
function return_date_long_time() {
var date = new Date();
// var n = d.toLocaleDateString(); // old approach - unreliable
// Date assembly
var dd = date.getDate(); // returns the day of the month (from 1 to 31)
if( dd < 10 ) dd = "0" + dd;
var MM = date.getMonth() + 1; // returns the month (from 0 to 11)!
if( MM < 10 ) MM = "0" + MM;
var yyyy = date.getFullYear(); // Returns the year (4 digits)
// time assembly
var hh = date.getHours(); // Returns the hour (from 0-23)
if( hh < 10 ) hh = "0" + hh;
var mm = date.getMinutes(); // Returns the minutes (from 0-59)
if( mm < 10 ) mm = "0" + mm;
var ss = date.getSeconds(); // Returns the seconds (from 0-59)
if( ss < 10 ) ss = "0" + ss;
// “Output”
return( yyyy + "-" + MM + "-" + dd + " " + hh + ":" + mm + ":" + ss );
}
if( document.GetLine( 1 ) == ".LOG" ) {
document.selection.EndOfDocument();
document.writeln( "" );
document.writeln( return_date_long_time() );
}