Sublime Text 3 Insert Date time, etc.

Source: Internet
Author: User
Tags month name



Sublime Text does not have the ability to insert date and time, but it can be implemented via plug-ins, which is also a powerful embodiment of Sublime extensibility. The detailed steps are as follows:



1. Menu bar: Tools--New Plugin ...



2. A plug-in template file is opened and the following content is used to overwrite


Import datetime, getpass
Import sublime, sublime_plugin

Class AddDateTimeStampCommand(sublime_plugin.TextCommand):
     Def run(self, edit):
         Self.view.run_command("insert_snippet",
             {
                 # "contents": "%s" % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S %A")
                 # Can be adjusted according to your needs (refer to the date and time format below)
                 "contents": "/**""\n"
                 " * ""\n"
                 " * @author: author""\n"
                 " * @dateTime: " "%s" %datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") +"\n"
                 " * @description: ""\n"
                 " */"
             }
         )


3. Ctrl+s Save the file, enter the file name add_date.py, can be arbitrarily defined, and then confirm that the location of the save is packages/user/add_date.py



4. Bind shortcut keys, in the menu bar: Preferences, Key Bindings, user, use the following content to overwrite


[
    {"keys": ["ctrl+shift+f5"], "command": "add_date_time_stamp" }
]


5. Save the shortcut key setting in the previous step, and try it in the place where you need to insert it! The effect is as follows:


/**
 *
 * @author:      author
 * @dateTime:    2015-08-12 11:42:34
 * @description:
 */
 class Demo {
 
 }

Reference: http://blog.upall.cn/1419.html

Appendix (Format of Strftime):

%a Week abbreviation

%A Week full Name

%b month abbreviation

%B Month Full Name

Time string for the date of%c standard

After two digits of the%c year

The day ordinal of a month in%d decimal notation

%d Month/day/year

%e the day ordinal of a month in a two-character field, in decimal notation

%F year-month-day

%g two digits of the year, using week-based

%G year, using week-based

%h Abbreviated month name

%H 24-Hour Hour

%I 12-Hour Hour

%j decimal indicates the day ordinal of the year

%m the month represented by decimal

%M minutes in a 10 o'clock-hour representation

%n New Line character

%p equivalent display of the local AM or PM

%r 12 hours of time

%R display hours and minutes: hh:mm

%s number of seconds in decimal

%t Horizontal Tab

%T display time seconds: hh:mm:ss

%u days of the week, Monday for the first day (values from 0 to 6, Monday to 0)

%u year of the week, put Sunday as the first day (value from 0 to 53)

%V Week of the year, using week-based

%w Decimal Day of the week (value from 0 to 6, Sunday is 0)

%W Week of the year, Monday as the first day (value from 0 to 53)

Date string for%x standard

Time string for%x standard

%y decimal Year without century (values from 0 to 99)

%Y 10 year with century part

%z,%z the time zone name and returns a null character if the time zone name cannot be obtained.

Percent hundred percent semicolon


Sublime Text 3 Insert Date time, etc.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.