Q: \time command?

John W. Shipman john at nmt.edu
Fri Apr 12 12:00:29 CEST 2002


On Thu, 11 Apr 2002, Andreas Hadjiprocopis asked:

+--
| I was wondering whether the \today command may be adjusted so as to
| give me the current time as well (e.g. the time the document was
| formatted with latex)
+--

Below my .signature you will find the macros I use for timestamping
documents in the ANSI standard order (year-month-day hour:minute).

Best regards,
John Shipman (john at nmt.edu), Applications Specialist, NM Tech Computer Center,
Speare 128, Socorro, NM 87801, (505) 835-5950, http://www.nmt.edu/~john
  ``Let's go outside and commiserate with nature.''  --Dave Farber

================================================================
% today.tex: Macro to print today's date
%--
% Author: John W. Shipman, NM Tech Computer Center,
%   Socorro, NM 87801; john at nmt.edu
%--
% EXPORTED FUNCTIONS:
%   \today: Outputs today's date as ``yyyy-mm-dd''
%   \now: Outputs the current time as ``hh:dd''
%   \timestamp: \today, plus one space, plus \now
%--
\newcount\minute	% Current minute within the hour
\newcount\hour		% Current hour (24-hour type)
\newcount\hourMins  % Temporary for taking hour modulo 60
%
% - - -   \ n o w   - - -
%
\def\now%
{% Displays today's time as ``hh:mm''
%  The \time macro gives the minutes since midnight.  Compute
%  the whole hours by dividing this by 60, then find the
%  minute by effectively taking the minutes modulo 60.
%
  \minute=\time    % Number of minutes since midnight
  \hour=\time \divide \hour by 60 % Get hours
  \hourMins=\hour \multiply\hourMins by 60
  \advance\minute by -\hourMins % Hours modulo 60
%
  \zeroPadTwo{\the\hour}:\zeroPadTwo{\the\minute}%
}% --- \now ---
%
% - - -   \ t i m e s t a m p   - - -
%
\def\timestamp%
{% Displays ``yyyy-mm-dd hh:mm''
  \today\ \now
}% --- \timestamp ---
%
% - - -   \ t o d a y   - - -
%
\def\today%
{% Displays today's date and time as ``yyyy-mm-dd hh:mm''
  \the\year-\zeroPadTwo{\the\month}-\zeroPadTwo{\the\day}%
}% --- \today ---
%
% - - -   z e r o P a d T w o   - - -
%
\def\zeroPadTwo#1%
{% Left zero pad of the argument to 2 digits.  The argument
%  should be a number between 1 and 99.  This macro outputs
%  a `0' if the argument is less than ten, then it outputs
%  the argument.
%
  \ifnum #1<10 0\fi    % Conditionally output a zero
  #1%    Then output the argument
}% --- \zeroPadTwo ---






More information about the texhax mailing list