Important: Please read the Qt Code of Conduct -

How to add the current time into Qt Creator files template?

  • Hello all!

    The issue: I need to add current timestamp into the file templates and get an ability to get it automatically at time of file creation. Is there system variables that will be used for the time inside of templates?

    This not working

    %YEAR%: Year
    %MONTH%: Month
    %DAY%: Day of the month
    %DATE%: Date
    %USER%: User name
    %FILENAME%: File name
    %CLASS%: Class name (if applicable)
    %$VARIABLE%: Contents of environment variable VARIABLE.

    There are for example file.cpp template from Qt Creator

    #include "%{HdrFileName}"
    %{JS: Cpp.openNamespaces('%{Class}')}
    @if '%{IncludeQSharedData}'
    class %{CN}Data : public QSharedData

    Is there specially defined variable %{Time} that might be used to auto-timestamp in this template?

  • Solution found. Through JS implementation to template file. Something like this:

    	var time = new Date();
    	time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();

Log in to reply