notepad++如何插入时间

37 篇文章 0 订阅
3 篇文章 0 订阅

如何使用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的脚本。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值