Every time I try to create a copyright profile in IntelliJ (or PyCharm), I find myself googling around the web trying to find out how to get the month name, e.g. August, into the template. Unfortunately, the IntelliJ documentation is not very helpful by just saying:
In short, it can be done via
$today.format("MMMM"), as the
DateInfo implements the syntax from
java.text.SimpleDateFormat, which has a long list of formatting options:
However, the important part is further below:
Month: If the number of pattern letters is 3 or more, the month is interpreted as text; otherwise, it is interpreted as a number.
- Letter M produces context-sensitive month names, such as the embedded form of names. Letter M is context-sensitive in the sense that when it is used in the standalone pattern, for example, “MMMM”, it gives the standalone form of a month name and when it is used in the pattern containing other field(s), for example, “d MMMM”, it gives the format form of a month name. For example, January in the Catalan language is “de gener” in the format form while it is “gener” in the standalone form. In this case, “MMMM” will produce “gener” and the month part of the “d MMMM” will produce “de gener”. If a DateFormatSymbols has been set explicitly with constructor SimpleDateFormat(String,DateFormatSymbols) or method setDateFormatSymbols(DateFormatSymbols), the month names given by the DateFormatSymbols are used.
- Letter L produces the standalone form of month names.
It’s important to use at least 3 letters
M to have the month be printed in text form otherwise, you will get the month’s number.
With that in mind, one can now provide a decent copyright profile in IntelliJ, well, to my liking at least, anyway:
Since: $today.format("MMMM") $today.year Author: $username Name: $file.fileName Description: Copyright $today.year Gerald Venzl Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
/* * Since: January 2022 * Author: gvenzl * Name: Test.java * Description: * * Copyright 2022 Gerald Venzl * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */
One thought on “How to get the month name in the IntelliJ copyright velocity template”