Hitachi

JP1 Version 11 JP1/Advanced Shell Description, User's Guide, Reference, and Operator's Guide 


8.4.7 date command (displays the system date and time)

Syntax

date [-u] [-d date-information-string | -r elapsed-seconds] [+format]

Description

This command displays the system date and time.

Arguments

-u

--utc

--universal

Specifies that the date is to be displayed in UTC (Coordinated Universal Time).

-d date-information-string

--date=date-information-string

Specifies the date and time to be displayed as a date-information string. If more than one information string is specified, the last string specified takes effect. For the supported date-information strings, see Date-information strings that can be specified in the -d option.

-r elapsed-seconds

Specifies that the display is to be of the date and time after the amount of time specified by elapsed-seconds had elapsed since the beginning of the UNIX epoch (UTC January 1, 1970, 00:00:00). The value specified in elapsed-seconds can range from -1009875600 to 2147440447. The output result cannot be guaranteed if the specified value is outside this range.

+format

Specifies a display format for the date and time using format specification codes. The format specification codes for the strftime function (OS's API) can be used. For details about the supported format specification codes, see Supported format specification codes, below.

If this argument is not specified, the display format for the date and time will be %Y/%m/%d %A %H:%M:%S %Z.

Supported format specification codes

In the argument that begins with a plus sign (+), you can specify the format specification codes for the strftime function (OS's API). These format specification codes vary according to the OS. For the format specification codes supported by your OS, see the information about the strftime function in the OS documentation.

The following table shows the strftime function of each OS and typical format specification codes that are unique to JP1/Advanced Shell and can be uniquely used.

Format specification code

Meaning

%a

Abbreviation for the day of the week

%A

Full name for the day of the week

%b

Abbreviation for the month

%B

Full name for the month

%c

Date and time display based on the locale

%d

Day of the month as a decimal number (01 to 31)

%H

Time in the 24-hour clock (00 to 23)

%I

Time in the 12-hour clock (01 to 12)

%j

Number of days since the beginning of the year as a decimal number (001 to 366)

%m

Month as a decimal number (01 to 12)

%M

Minute as a decimal number (00 to 59)

%p

AM or PM based on the current locale

%S

Second as a decimal number. The range of values displayed varies according to the OS depending on support for leap seconds.

%s

Number of seconds elapsed from the epoch (UTC January 1, 1970, 00:00:00).

If the code is not specified for the ADSH_CMDDATE_FORMAT environment variable, the code can be used with Linux, AIX and HP-UX (processing with the strftime function).

If the code is specified for the ADSH_CMDDATE_FORMAT environment variable, the code can be used in all OSs (executing conversion that is unique to JP1/Advanced Shell).

%U

Week as a decimal number (00 to 53). The first Sunday of the year begins the weeks.

%w

Day of the week as a decimal number (0 to 6, where 0 indicates Sunday)

%W

Week as a decimal number (00 to 53). The first Monday of the year begins the weeks.

%x

Date based on the current locale

%X

Time based on the current locale

%y

Last two digits of the year as a decimal number (00 to 99)

%Y

Year as four decimal digits

%Z

Time zone name. If the time zone is unknown, this information is not displayed.

%%

Percent symbol (%)

Date-information strings that can be specified in the -d option

Specify as explained below the date-information string that you want the date command to display:

The elements of the date-information string can be specified as uppercase or lowercase letters. If a specified value is earlier than 1970-01-01 00:00:00 or later than 2038-01-19 03:14:07 in UTC, the command issues the error message date: Invalid date: specified-value and then terminates with an error. In AIX, if a specified value is later than 2038-01-19 03:14:07 in the local time zone, the command issues error message date: Invalid date: specified-value and then terminates with an error. If the null character is specified as the date-information string, the command displays 00:00:00 on the current date.

The date information string is specified as a space-separated string. However, when strings of alphabetic characters, numeric characters, and symbols are specified together, strings of different types can be specified next to each other without spaces. For example, two alphabetic characters cannot be specified together without a space, but numeric characters and alphabetic characters can be specified next to each other without a space in between.

The following explains the permitted elements of a date-information string and the syntax.

The specified absolute and relative date and time values are obtained in the order shown below. In steps 2 through 4, if the value converted to seconds is outside the range from 0 to 2147483647, an error might result regardless of the final results.

  1. Obtains the current date and time or the date and time specified as an absolute date.

  2. Adds the shift in day of week specified as a relative date to the value obtained in step 1. If date specification is specified as an absolute date, the number of days of week to be shifted (DAY) is not added, if specified.

  3. Adds or subtracts all results obtained based on the specified number of years and months to be shifted (DATE) as a relative date to or from the value obtained in step 2.

  4. Adds or subtracts all results obtained based on the specified number of days to be shifted (DATE), number of hours and minutes to be shifted (DATE), and number of seconds to be shifted (DATE) specified as a relative date to or from the value obtained in step 3.

Steps 2 through 4 obtain the amount to be shifted from the date and time subject to calculation.

For example, if the current date and time is 2014-04-30 at 10:10:10 and date -d "Fri, 1 year 1 month 1 day 1 hour 1 min 1 sec" is specified, the following calculation occurs:

1. Obtain the current date and time.

[Figure] The result is 2014-04-30 (Wednesday) at 10:10:10.

2. Add the number of days from 2014-04-30 (Wednesday) to the next Friday.

[Figure] The result is 2014-05-02 (Friday) at 10:10:10.

3. Add 365 days and the number of days in May 2014.

[Figure] The result is 2015-06-02 (Monday) at 10:10:10.

4. Add one day, one hour, one minute, and one second.

[Figure] The result is 2015-06-03 (Tuesday) at 11:11:11.

Specifications that require caution when combining different syntax in date-information strings

Some ways of specifying date-information strings require caution when using a combination of absolute and relative date specification.

If, as follows, you specify a signed relative date specification after the [YY]YYMMDD or hh[mm] syntax, an error occurs. If you want to combine the [YY]YYMMDD or hh[mm] syntax with a signed relative date specification, make sure that the [YY]YYMMDD or hh[mm] syntax is specified last.

C:\TEMP>date -d "20151112 -10 days"
date: Invalid date: 20151112 -10 days

C:\TEMP>date -d "-10 days 20151112"
2015/11/02 Monday 00:00:00 JST

C:\TEMP>date -d "0955 -1 hours"
date: Invalid date: 0955 -1 hours

C:\TEMP>date -d "-1 hours 0955"
2016/09/28 Wednesday 08:55:00 JST

When alphabetic characters, numeric characters, or symbols appear next to each other in character strings, any spaces between them are not handled as separators. Therefore, the following example is interpreted in the same way as date -d "10-November-15 days", as one day after November 10th, 2015. When using an absolute date specification whose interpretation might differ according to the relative date specification that follows it, make sure that the absolute date is specified last.

C:\TEMP>date -d "10-November -15 days"
2015/11/11 Wednesday 00:00:00 JST

If, as follows, you specify signed numeric characters after hh:mm[:ss] and ST, the signed numeric characters are interpreted as +hh[mm] or -hh[mm]. Therefore, in the case of the following example, a date and time are displayed that are one hour ahead of the time obtained by converting 12:11:10 UTC-10 to JST.

C:\TEMP>date -d "20151110 12:11:10 -10 hours"
2015/11/11 Wednesday 08:11:10 JST

Common format specification code that is unique to JP1/Advanced Shell

JP1/Advanced Shell uniquely edits the format specification code specified with the ADSH_CMDDATE_FORMAT environment variable without using the strftime function. Therefore, common output result can be obtained regardless of difference in specifications of the strftime function among OS.

The format codes that can be specified and their behaviors are as follows:

ADSH_CMDDATE_FORMAT environment variable

Conversion process that is unique to JP1/Advanced Shell is executed only if the code is executed by the ADSH_CMDDATE_FORMAT environment variable.

Environment variable name

Specification value

ADSH_CMDDATE_FORMAT

s

If you specify s for the ADSH_CMDDATE_FORMAT environment variable, number of seconds elapsed from the epoch (UTC January 1, 1970, 00:00:00) is output. If you specify s, the code is operated in the range of the common format process described below.

Syntax type

%[flag][field width]

- flag~[ _ | - | 0 | ^ | # ]

_(underscore)

This command executes padding (filling up blanks) for the result character string of values spaces (blank characters).

- (hyphen)

This command left-aligns the result character string in fields.

This command executes padding for spaces (blank characters) for empty field.

0

This command executes zero-padding for the result character string.

^

This command converts alphabetic characters in the result character string with uppercase letters.

However, the format specification code s is ignored because there is not a meaning.

#

This command converts uppercase and lowercase of the result character string.

The format specification code s is ignored because there is not a meaning.

- Field width

This command specifies the width of the field to which a numerical value is output.

This command executes padding with spaces (blank characters) if padding is not specified.

If the format syntax is not correct, this format specification (from % to s of the corresponding format) is output as characters.

Return codes

Return code

Meaning

0

Normal termination

1 or greater

Error termination

Notes

Examples