Obtain the "Hour," "Minute," and "Second" from the current time (OS time zone)

This section describes the process on how to obtain the "Hour," "Minute," and "Second" from the EdgeStreaming logic that obtains the current date and time.

This process outputs results such as the following:

Example: when "Format" is "hh:mm:ss" and "Add milliseconds" is selected

If the obtained time zone of the OS is "2021-06-01T06:04:36.9060502Z", the output value becomes "06:04:36.906".

Description of the processing

The current date and time is obtained and the "Hour," "Minute," "Second," and "Millisecond" are output.

The following example shows how to create a mapping definition for outputting the result in the "hh:mm:ss:SSS" format.

= Remarks =

If the standard formats don't include the format that you want to output, you can specify a custom format using the Date/Time formatting(Custom) logic. For details on the Date/Time formatting(Custom) logic, refer to Obtain the "Year," "Month," and "Day" from the current time (OS time zone).

Key features

Current date/time (OS time zone)

This logic outputs the current date and time.

It can be set from Date > Basic > Current date/time (OS time zone) of the tool palette.

Date/Time formatting(Standard format)

This logic formats the date and time to the selected format.

It can be set from String > Date > Date/Time formatting(Standard format) of the tool palette.

Operation procedure

This section explains the procedure using an example that takes the OS time zone of the IoT gateway that is executing Runtime and outputs only the time in the "06:04:36.906" format.

1. Create a script.

For information about how to create a script, refer to First Step Guide.

The descriptions in this procedure are based on the following scripts:

2. On the script canvas, double-click mapping_1.

The Mapper editor is displayed.

3. Drag and drop the following logics from the tool palette onto the Mapper editor:

  • Date > Basic > Current date/time (OS time zone) (to obtain the current date and time)

  • String > Date > Date/Time formatting(Standard format) (to specify the date and time format that you want to output)

The logics are placed on the Mapper editor.

4. Enter the property of the placed logic.

  1. Double-click the Date/Time formatting(Standard format) logic.

    The Date/Time formatting(Standard format) Logic Property dialog box is displayed.

  2. Select a format from the Format pulldown menu.

    In this example, hh:mm:ss is selected.

  3. Select Add milliseconds.

    In Output format, a sample of the actual output format is displayed.

  4. If necessary, also enter a comment in Comment and click Finish.

  5. If necessary, double-click the Current date/time (OS time zone) logic, enter a comment in Comment, and click Finish.

5. Drag and drop the Current date/time (OS time zone) logic onto the Date/Time formatting(Standard format) logic.

The mapping link from the Current date/time (OS time zone) logic to the Date/Time formatting(Standard format) logic is displayed.

6. Drag and drop the Date/Time formatting(Standard format) logic onto the output destination.

The mapping link to the output destination from the Date/Time formatting(Standard format) logic is displayed.

7. Save the script.

For information about how to save a script, refer to First Step Guide.

 

The following result is obtained if you execute the script: