Insert current datetime in Visual Studio Snippet

后端 未结 1 1485
独厮守ぢ
独厮守ぢ 2020-12-16 17:58

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.

相关标签:
1条回答
  • 2020-12-16 18:33

    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
    

    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.

    0 讨论(0)
提交回复
热议问题