How to insert time in notepad++

How to use notepad++ to insert the date and time in the time format you want in the text?

Reference address: http://stackoverflow.com/questions/27950710/in-notepad-how-can-i-insert-the-current-date-and-time

Specific content:

wrote
Try "Python Script" plugin

I prefer to use the Python Script plugin as documented here: https://ardamis.com/2014/03/09/adding-an-insert-datestamp-or-timestamp-macro-to-notepad-plus-plus/ because it gives me total control over how I want to the datetime stamp formatting to look, and it also allows me to create macro scripts for inserting other types of values that I want to compute.

Install "Python Script" MANUALLY

Please note that you must download the Python Script plugin from http://npppythonscript.sourceforge.net/download.shtml because downloading it from the Plugin Manager in Notepad++ doesn't always work. (See this thread for details.)

Write "Time.py" script

Then you can write a simple script like this:

import time
# import sys
timeStr = time.strftime( '%Y-%m-%d' + ' @ ' + '%I:%M %p' )
# sys.stdout.write(timeStr)
editor.addText( timeStr )
You can change the format string as you wish. This allows you to have total control over the text output. (See Python 2's time.strftime documentation for details.)

Then save the script to this filename:

"%AppData%\Notepad++\plugins\Config\PythonScript\scripts\Time.py"
Create "menu item" inside "Python Script"

Navigate here: Menu bar -> Plugins -> Python Script -> Configuration like this:



Then you can add the script like this:



Assign hotkey

Then, when you restart Notepad++, you can assign the script to a shortcut like this by going to Menu bar -> Settings -> Shortcut Mapper -> Plugin Commands -> Time:



Further reading

More documentation on the Python Script plugin is available here: PythonScript plugin documentation for Notepad++

 

Python's footsteps (written by myself)

ActionInsertDate.py

import datetime
now = datetime.datetime.now()
editor.addText(now.strftime('%Y/%m/%d'))

 

ActionInsertDateTime.py

import datetime
now = datetime.datetime.now()
editor.addText(now.strftime('%Y/%m/%d %H:%M'))

 

 [Remarks] To be recognized by notepad++, the python script written by yourself needs to be placed in the directory specified below:

wrote
npp.7.2.1.bin\plugins\Config\PythonScript\scripts

 

 

The referenced picture was lost during pasting of the content above. Please download the rar file in the attachment, which contains the pdf file of the modified article and two python scripts written by myself.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326612803&siteId=291194637