Obtain the "Year," "Month," and "Day" from the current time (OS time zone)

This section describes the process to obtain the "Year," "Month," and "Day" from the EdgeStreaming logic that obtains the current date and time.

This process outputs results such as the following:

Example: when "Format" is "1/2/2006"

If the obtained time zone of the OS is "2021-03-03T06:04:36.9060502Z", the output value becomes "3/3/2021".

Description of the processing

The current date and time is obtained and only the "Year," "Month," and "Day" are output.

The following example shows how to create a mapping definition for outputting the result in the "M/D/YYYY" format.

= Remarks =

You can also select the format from a standard format using the Date/Time formatting(Standard format) logic. For details on the Date/Time formatting(Standard format) logic, refer to Obtain the "Hour," "Minute," and "Second" 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(Custom)

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

It can be set from String > Date > Date/Time formatting(Custom) 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 year, month and day in the "M/D/YYYY" 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(Custom) (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(Custom) logic.

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

  2. Enter the Format.

    In this example, "1/2/2006" is entered. The character string input for the format represents the following date format:

    • 1: Month

    • 2: Day

    • 2006: Year (four digits)

    For details on character strings in a format that indicates a date, refer to Mapper Reference.

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

  4. 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(Custom) logic.

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

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

The mapping link to the output destination from the Date/Time formatting(Custom) 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: