Question

I would like to be able to insert a current timestamp into a document in brackets using a hotkey, or a menu item or some other menu - for example

Timestamp: '20131009T232028'

would be a good format.

It seems to me that I should be able to do it with the snippets extension, and it even looks to me like that functionality might already be implemented, but not sure how to get the mustache templates in javascript.json to output the correctly formatted date.

Anyone have an example of how to do this?

Was it helpful?

Solution

It doesn't look like that exact format is supported by the Snippets extension, but you can get something like this pretty easily:

timestamp: 9/17/2013 10:09:18 AM

To add this template:

  1. Help > Show Extensions Folder
  2. Navigate to user/jrowny.brackets.snippets/data
  3. Open javascript.json
  4. Add this item:

    {
        "name": "Timestamp",
        "trigger": "t",
        "usage": "t",
        "description": "Insert timestamp into file",
        "template": "timestamp: $${DATETIME}"
    }
    
  5. Restart Brackets

  6. Now you can insert the snippet in any file by typing "t" followed by Ctrl+Alt+V

If you need a very specific date format, you should be able to patch the source code by editing SnippetPresets.js where your extension is installed. (Don't forget to send your improvements back to the original author as a pull request!)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top