You can use the function org-insert-time-stamp
:
org-insert-time-stamp is a compiled Lisp function in ‘org.el’.
(org-insert-time-stamp TIME &optional WITH-HM INACTIVE PRE POST EXTRA)
Insert a date stamp for the date given by the internal TIME.
See ‘format-time-string’ for the format of TIME.
WITH-HM means use the stamp format that includes the time of the day.
INACTIVE means use square brackets instead of angular ones, so that the
stamp will not contribute to the agenda.
PRE and POST are optional strings to be inserted before and after the
stamp.
The command returns the inserted time stamp.
For example:
(with-temp-buffer
(org-insert-time-stamp (string-to-number (car (process-lines "date" "+%s")))
t))
AKA
(with-temp-buffer
(call-process "date" nil t nil "+%s")
(org-insert-time-stamp (read (point-min-marker)) t))
both give
"<2018-04-11 Wed 22:25>"
You can play around with the precise formatting via either the defconst
org-time-stamp-formats
:
org-time-stamp-formats is a variable defined in ‘org.el’.
Its value is ("<%Y-%m-%d %a>" . "<%Y-%m-%d %a %H:%M>")
This variable may be risky if used as a file-local variable.
Documentation:
Formats for ‘format-time-string’ which are used for time stamps.
or by passing a format-time-string
-style format string as the EXTRA
argument. To add seconds to the resulting timestamp, for example, you can write:
(with-temp-buffer
(call-process "date" nil t nil "+%s")
(org-insert-time-stamp (read (point-min-marker)) t nil nil nil ":%S"))
which gives:
"<2018-04-11 Wed 22:36:23>"
but I would be wary of how robust Org is in the face of exotic timestamp formats.