If what you want is just a timestamp, you can use
(defvar user-time-format (eval-when-compile (or (getenv "STRFTIME") "%Y-%m-%d %a %H:%M:%S %Z")) "The time format for the user to set.") (defun user-time-format (&optional insert) "Return or insert the time string according to `user-time-format'." (interactive "P") (let ((str (format-time-string user-time-format))) (if insert (insert str) (if (called-interactively-p 'interactive) (message "%s" str) str))))
except you would set user-time-format to "%Y-%m-%dT%H-%M-%S".
However, your question raises an interesting issue, so let us discuss it too.
Your insert-dateutc is fine (but see below), but it inserts the date instead of returning it, so foo has to correct that:
(defun foo () (with-temp-buffer (insert-dateutc) (buffer-string))) (format "timestamp = [%s]" (foo)) ==> "timestamp = [2015-11-18T16:37:12]"
Finally, take a look at C-h f shell-command RET. It says discourages the use of this function in lisp code, recommending call-process instead:
(with-temp-buffer (call-process "date" nil t nil "+%Y-%m-%dT%H:%M:%S") (buffer-substring-no-properties 1 (line-end-position 0))) ==> "2015-11-18T16:47:27"
current-time-stringor usecurrent-timewithformat-time-string.(shell-command ...)part infoo1, but it does the same thing AFAIK.call-processorstart-process, to get more control. Otherwise, theshell-commandcall you are using puts the output of theprintfcommand in the current buffer, at point. You could wrap the call inwith-current-buffer-windowor similar (in which case you don't need the second arg), to recuperate the output.(defun foo1 () (format "this is the date-time %S" (shell-command "date +\"%Y-%m-%dT%H:%M:%S\"" t)))is without theprintf, but with the same bad results. Theprintfwas only to avoid a newline. What exactly should I do withcall-process?format-time-stringI'm home free. . .