notepad++如何插入时间

如何使用notepad++在文本内插入自己想要的时间格式的日期和时间呢?

参考地址:http://stackoverflow.com/questions/27950710/in-notepad-how-can-i-insert-the-current-date-and-time

具体内容:

写道
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的脚步(自己写的)

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'))

 【备注】自己写的python脚本要想被notepad++认出来,需要放在下面指定的目录中:

写道
npp.7.2.1.bin\plugins\Config\PythonScript\scripts

上面的内容粘贴过程中丢失了参考的图片。请大家下载附件中的rar文件,里面包含有改文章的pdf文件,以及我自己编写的2个python的脚本。

猜你喜欢

转载自kanpiaoxue.iteye.com/blog/2340937
今日推荐