Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #29376
    jic
    Participant

    Greetings.

    I would like to change the format of Insert/Date Time SHIFT-F5 menu to produce the YYYY-MM-DD HH:MM:SS.mmm instead of the default. Is this a possibility? Thanks.

    josé

    #29377
    Patrick C
    Participant

    I’ve got an old script that gets close, perhaps it helps.

    // 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 );
    }
    
    document.write( return_date_long_time() );
    #29378
    jic
    Participant

    Thanks, Patrick. That is what I am doing now: Using a script to make it what I want. But, it would be nice if EmEditor would have an option to format the output to a desirable date, time or date+ time formats. Thanks, though.

    #29382
    Yutaka Emura
    Keymaster

    You can use the “Date and Time” command instead of the “Time and Date” command, and set the date/time format in the Format page of the Customize dialog box.

    #29384
    jic
    Participant

    Thanks. That is exactly what I was looking for.

    #29386
    jic
    Participant

    By the way, this is the option I chose: yyyy-MM-dd HH:mm:ss.ms which provides exactly what I want: 2023-09-08 07:54:27.5427

    thanks.

    #29591
    jic
    Participant

    Sorry to bring this up again, but is there a way to bring the milliseconds in the Format page of the Customize dialog box? I tried ms but tat brings minus and seconds and puts them together.

    #30094
    J Melvin
    Participant

    Along the same lines, is there a way to add an automated macro or other technique to automatically update the date and time a document was edited, within the body of the document, in case a user forgets to press SHIFT-F5 .

    #30095
    Yutaka Emura
    Keymaster

    How about the Notepad-Compatible Diary option (File page of configuration properties)?

    #30134
    netsking
    Participant

    Dear Yutaka, That’s cool function. I am wondering if it is possible to customize the time-date in Notepad-Compatible Diary mode?
    It uses system default format: time-date. I would like date-time.

    #30135
    Yutaka Emura
    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() );
    }
    
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.