在 Visual Studio Snippet 中插入当前日期时间 [英] Insert current datetime in Visual Studio Snippet
本文介绍了在 Visual Studio Snippet 中插入当前日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道我可以插入当前日期的方法吗?在 Visual Studio 2008 片段中的时间?我想要的是我的 .snippet 文件正文中的类似内容...
Does anyone know of a way that I can insert the current date & time in a visual studio 2008 snippet? What I want is something like this in the body of my .snippet file...
<Code Language="csharp">
<![CDATA[
// $DateTime$
// more code here for my snippet...
</Code>
推荐答案
没有可用于片段的 DateTime 函数,但这里有一个宏可以插入当前的 DateTime:
There are no DateTime functions available for snippets but here is a macro that will insert the current DateTime:
Sub PrintDateTime()
If (Not IsNothing(DTE.ActiveDocument)) Then
Dim selection As TextSelection = DTE.ActiveDocument.Selection
selection.Insert(DateTime.Now.ToString())
End If
End Sub
您可以使用 Alt + F8 打开宏浏览器并创建一个新模块并将上面的代码粘贴到生成的模块中.
You can open your macro explorer with Alt + F8 and create a new module and paste the code above inside the module that is generated.
然后创建一个新的键盘快捷键并将其绑定到您的宏.
Then create a new keyboard shortcut and bind it to your macro.
这篇关于在 Visual Studio Snippet 中插入当前日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文