[texhax] tip: time-am-pm

Ron RJF Fehd ron.fehd.macro.maven at gmail.com
Mon Jul 11 22:52:28 CEST 2016


I wanted to add a time-stamp to a document
and found that \time contains the number of minutes since midnight.

The TeX Reference Manual, by David Bausum
contains a function to format time to civilian time

%%  name: \texmf-local\tex\latex\local\format-time-am-pm.sty
%%description: format time as minutes since midnight
%%             to hh:mm am|pm
%%    purpose: provide time-stamp
%% usage:
%\usepackage{format-time-am-pm}
%date-time-stamp: \today, \timeAMPM{\the\time}
%%source: TeX Reference Manual, by David Bausum
%%        time, civilian, pg 290:291
%%        for military time see ifnum, pg 144
\def\timeAMPM#1% expected value=\the\time
{{\count20=#1
  \count22=\count20
  \divide  \count20 by  60
  \count21=\count20
  \multiply\count21 by -60
  \advance \count22 by \count21
  \ifnum\count20<12\def\textAmPm{ am}
     \else         \def\textAmPm{ pm}
     \fi
  \ifnum\count20=0
        \count20=12
     \fi
  \ifnum\count20>12
     \advance\count20 by -12
     \fi
  \the\count20:%
  \ifnum\count22<10 0\fi
  \the\count22\textAmPm
}}%end.timeAMPM

Ron Fehd  Atlanta GA
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/texhax/attachments/20160711/cd4dbad9/attachment.html>


More information about the texhax mailing list