stardate - convert between stardates and other calendars
] [ date
interprets the date
s specified on its command line, and
outputs them in the formats specified by the option
If no date
s are specified, the current time, read from the system clock,
is used. If no option
s are specified, dates are output in the form of
stardates. Consequently, if stardate
is invoked with no arguments, it
outputs the current time as a stardate. This performs much the same job as
(1), but with a more interesting form of output.
Dates on output are always rounded down, and so in some cases will generate
different output if reused as input. This rounding is always such that the
output date is the latest time, expressible in the format being used, that is
no later than the time specified as input.
This program handles dates from 0001=01=01 (Julian calendar) up to (currently)
(2^64 - 1) seconds later, which is beyond the year (5 x 10^11). Any date
within this range can be input or output in any of the formats the program
supports. Consequently, any date the program outputs will be accepted as
input. The only exception is for dates within the first half second of the
acceptable range, where the value output in the quadcent calendar,
'' (chosen due to the rounding mentioned above),
is actually outside the acceptable range.
The stardate code is based on information in version 1 of the Stardates in
Star Trek FAQ
, which is regularly posted to the USENET newsgroup
- Output the date as a stardate. n, if given, specifies the number of
digits output after the decimal point. If not specified, it defaults to 2.
The output looks like
When 2 decimal places are used, the output of the current time changes every
172.8 seconds. (Actually, because of the resolution of C time, four-fifths of
the changes are 173 seconds after the previous change, and the other fifth are
172 seconds after.)
- Output the date as a date in the Julian calendar, with UTC time. The
output looks like
- Output the date as a date in the Gregorian calendar, with UTC time. The
output looks like
- Output the date as a date in the Quadcent calendar, with UTC time. The
output looks like
This calendar is explained in detail in the Stardates in Star Trek FAQ
Briefly, it uses seconds that are approximately 1.00066 SI seconds long, and
has no leap years. Each 400 years in this calendar is exactly as long as 400
years in the Gregorian calendar, but all years in the quadcent calendar are
the same length.
- Output the date in the form of the traditional Unix time. This is a number
of seconds since midnight UTC on 1970-01-01. The output looks like
- Output the date in the form of the traditional Unix time, in hexadecimal.
The output looks like ``U0xnnnnnnnnn''.
s may be specified in any of the output formats, as described above,
with a few variations allowed. More precisely, the following forms are
- A stardate. The issue number, with the square brackets, is mandatory. The
fractional part is optional.
'' is midnight UTC on 2162-01-04; negative issue
numbers indicate times before that. If issue
is less than 20, the
number must be in the range [0, 10000). If equal to 20, [0, 5006). If greater
than 20, [0, 100000). The FAQ explains these range changes.
- A date in the Julian calendar, optionally with a time in UTC.
- A date in the Gregorian calendar, optionally with a time in UTC.
- A date in the Quadcent calendar, optionally with a time in UTC.
- A Unix time specification - a number of seconds since 1970-01-01. A
negative number indicates a time before 1970. In the forms with
``0x'', the number is in hexadecimal.
Case of alphabetic characters in input is ignored.
Andrew Main <firstname.lastname@example.org>
(1), Stardates in Star Trek FAQ
This program will not handle dates BCE.