Date and time on the visualization

In this tutorial we show how to display the current date and time on the visualization as well as different ways of formatting.

1. Clock update

We will start from a small portion of Lua code, that will allow us to obtain the current date and save it in a VAR variable.

function clock()

  set('VAR.clock',date())
end

The clock function invokes the Lua function- date. It returns the current date and time and saves the clk variable using the set function.

Date and time are displayed in the default format and should have the following form: <day name> <month name> <day> <hour>:<minute>:<second> <year>, e.g.: Wed Nov 7 14:50:00 2012.

2. Starting the clock

The code mentioned in section 1. does not perform any action until the clock() function is invoked. In order to get the time and date automatically updated, create a timer that will periodically invoke the clock()function. We will use timer.

  1. Add a new timer in Timers tab. You can add the description, e.g. „Clock” (optional).
  2. In Seconds field enter 0. The timer will be invoked every minute.

3. Click on Add command, in order to define the clock() function. In the displayed

window in the Name field enter C.LOGIC and in the Value field enter: clock().

From now on the clock will be updated every minute automatically.

3. Effect on the visualization

In order to see the effect on the visualization, add the element like Text and in the Chan- nel field enter the name of the VAR variable in which the date and time is saved. In this case it is VAR.clock variable.

4. Date and time formatting

In this section we present the ways of formatting the date and time. The following table li- sts all the available parameters that can be used to format dates and times. Examples re- late to the date of the 07.11.2012 (Wednesday) at 15:10:35. All parameters can be used with the date function mentioned above.

If the date function is invoked without any parameter (like in code from chapter 1, the %c parameter is used by default.

4.1. Usage

Below we present some examples of date and time formatting which can be used in the code from the first section of the tutorial.

Powered by BetterDocs

Select your currency
PLN Polish złoty
EUR Euro