Here is code that I use for a format-time-string for a fake calendar:
(defun mystcal-format-time (format-string time) "Format time %Y is the year. %m is the numeric month. %B is the full name of the month. %d is the day of the month, zero-padded, %e is blank-padded. %u is the numeric day of week from 1 (Monday) to 7, %w from 0 (Sunday) to 6. %A is the locale's full name of the day of week. %H is the hour on a 24-hour clock, %I is on a 12-hour clock, %k is like %H only blank-padded, %l is like %I blank-padded. %p is the locale's equivalent of either AM or PM. %M is the minute. %S is the second." (let* (output (start 0) (decoded-time (if (listp time) time (mystcal-decode-time time))) (turn (nth 0 decoded-time)) (minute (nth 1 decoded-time)) (hour (nth 2 decoded-time)) (day (nth 3 decoded-time)) (month (mystcal-month decoded-time)) (year (nth 5 decoded-time)) (weekday (mystcal-weekday-of-day day)) (hour12 (mod hour 12))) (save-match-data (while (string-match "%" format-string start) (let ((index (match-beginning 0))) ;; First copy non-format text (setq output (concat output (substring format-string start index))) ;; Process format codes here (let (fmted) (setq output (concat output (case (aref format-string (1+ index)) (?Y (number-to-string year)) (?m (number-to-string month)) (?B (mystcal-month-name month)) (?d (format "%02d" day)) (?e (format "%2d" day)) (?u (number-to-string (if (zerop weekday) 7 weekday))) (?w (number-to-string weekday)) (?A (mystcal-weekday-name (mystcal-weekday-of-day day))) (?H (format "%02d" hour)) (?k (format "%2d" hour)) (?I (format "%02d" (if (zerop hour12) 12 hour12))) (?l (format "%2d" (if (zerop hour12) 12 hour12))) (?p (if (< hour 12) "AM" "PM")) (?M (format "%02d" minute)) (?S "00"))))) (setq start (+ 2 index))))) (setq output (concat output (substring format-string start))) output))