To customize the time stamp in a particular file, set the
variable time-stamp-pattern in that file’s local variables
list (see Specifying File Variables).
You can change what pattern time-stamp will match against to
identify a template and where in the file to look for the pattern using
time-stamp-pattern; for details, see the variable’s built-in
documentation (with C-h v, see Help by Command or Variable Name).
As a simple example, suppose you want a manuscript to say the year and city of publication. You would like the year updated as you make revisions. You could have this line near the top of a file:
publishing_year_and_city = "Published nnnn in Boston, Mass.";
and the following comment at the end of the same file to tell
time-stamp how to identify and update that custom template:
// Local variables: // time-stamp-pattern: "Published %Y in Boston" // End:
This pattern says that the text before the start of the time stamp is
“Published ”, and the text after the end is “ in Boston”.
If time-stamp finds both the start and the end in one of the
first eight lines,
what is between will be updated as specified by the format, %Y in
this example. Since %Y requests the year, the result might look
like this:
publishing_year_and_city = "Published 2025 in Boston, Mass.";
By specifying a format of %Y, we get exactly the year
substituted; other parts of the default format (day, time and
author) are not part of this example pattern and so do not appear in the
result.
After changing the value of time-stamp-pattern
(or any file-local variable),
type M-x normal-mode so that Emacs notices.
Here is another example, with the time stamp inserted into
the last paragraph of an HTML document.
Since this template is at the end of the document, not in the first
eight lines, time-stamp-pattern starts with -10/ to tell
time-stamp to look at the last 10 lines.
The %% asks for the default format
(specified by time-stamp-format).
...
<p>Last modified: </p>
</body>
</html>
<!--
Local variables:
time-stamp-pattern: "-10/Last modified: %%</p>$"
End:
-->
By default the time stamp is
formatted according to your locale setting (see Environment Variables) and
time zone (see Time of Day in The Emacs Lisp Reference
Manual).
Set time-stamp-time-zone to override the time zone used.
See the built-in documentation for the variable time-stamp-format
for specifics on formatting and other variables that affect it.