NovaStar Program Reference / System / dispdate


Overview

The dispdate program prints a formatted date/time string. The program has the following purposes:

  • Given input date/time format specifier (see %-specifiers below), format the date/time string.
  • Given a time as a long integer from Linux clock (epoch time since Jan 1, 1970) and date/time format specifiers, format the date/time string.
  • Given a time, rounded to an interval. The roundtime can be expressed as count followed by time units (s, m, h, d, month, y). For example 5 minutes is expressed as 5m.

Command Line Usage

The command line syntax is:

dispdate [parameters...]

Command line Parameters

Parameter                     Description Default                        
D-T Date/time as MM/DD/YYYY-HH:MM:SS or
YYYY/MM/DD-HH:MM:SS,
where / can be characters /+-., (including space) and - or : are any non-digit.
D-T or -t Ltime must be specified.
+format Format string of the displayed date. The format is composed of ASCII character and field specifiers, consistent with Linux date command. In the output, each field specifier is replaced by its corresponding value (see the following table). All other characters are copied to the output without change. To display a % character, encode it as %%. The date utility always terminates its output with a newline character.
-help or --help Print the program usage.
-r roundtime Rounds the displayed time to the interval.
-t Ltime Input time as a long integer. D-T or -t Ltime must be specified.
-t Display time as a long integer.
--version Print the program version.

Format Specifiers

Specifier Description\
%a Locale's abbreviated weekday name.
%A Locale's full weekday name.
%b Locale's abbreviated month name.
%B Locale's full month name.
%c Locale's appropriate date and time representation.
%d Day of the month as a decimal number (01-31).
%D Date in the format mm/dd/yy.
%h A synonym for %b.
%H Hour (24-hour clock) as a decimal number (00-23).
%I Hour (12-hour clock) as a decimal number (01-12).
%j Day of the year as a decimal number (001-366).
%m Month as a decimal number (01-12).
%M Minute as a decimal number (00-59).
%n Insert a newline character.
%p Locale's equivalent of either am or pm.
%r 12-Hour clock time (01-12) using the AM/PM notation in the format
HH:MM:SS AM or HH:MM:SS PM
%S Seconds as a decimal number (00-61). The range of values for %S extends from 0 to 61 seconds to accommodate the occasional leap second or double leap second.
%t Insert a tab character.
%T 24-Hour clock time (00-23) in the format HH:MM:SS.
%U Week number of the year (Sunday as the first day of the week) as a decimal number (00-53).
%w Weekday as a decimal number (0 (Sunday)-6).
%W Week number of the year (Monday as the first day of the week) as a decimal number (00-53).
%x Locale's appropriate date representation.
%X Locale's appropriate time representation.
%y Year without century as a decimal number (00-99).
%Y Year with century as a decimal number.
%Z Time zone name, or no characters if no time zone can be determined.

Examples

# If not defined, compute the StartTime  as the beginning of the day for the StopTime
StartTime=${StartTime:-$(dispdate "$StopTime" "+%Y/%m/%d 00:00:00")}

# Set the end time to the current time if not defined.
if [ -z "$TIMEEND" ]; then TIMEEND=$(dispdate "+%m-%d-%Y+%H:%M:%S"); fi
TIMEEND=$(dispdate "$TIMEEND" "+%m-%d-%Y+%H:%M:%S")
# Compute the start time by subtracting time span from end time in seconds
tend=$(dispdate "$TIMEEND" -t)
tstrt=$((tend-$ TIMESPANSECS))
TIMESTART=$(dispdate "+%Y-%m-%d+%H:%M:%S" -t $tstrt)

Troubleshooting