Timestamp (Current Date & Time)
In this article, we will explore the use of Timestamp data in PandaSuite. Timestamp is an important concept for knowing the current date and time and using it in your applications.
⚡️ AVAILABLE TEMPLATE: Timestamp
Add this template to your account in just a few clicks. Modify and customize it freely.
In this article
Timestamp data
The Timestamp represents the number of seconds that have elapsed since January 1, 1970, at precisely midnight UTC. It is used as a reference for measuring and representing date and time. In PandaSuite, this variable is accessible from the Project data. This allows you to obtain the current date and time in your applications, based on the device's time.
For example, the Timestamp data corresponding to June 6, 2021, at 1:30 AM and 0 seconds is: 1622943024.
Displaying time in an application
To display the time in an application, follow these steps:
- Insert a text block into your screen.
- Add a data binding to the Content property.
- Choose Project > Context > Timestamp as the data source.
- Use the Format Date function to set the time display format.
- Select the desired formatting settings.
By using this approach, you can display the current time in your PandaSuite application according to the specified format.
Displaying date in an application
To display the date in an application, follow these steps:
- Insert a text block into your screen.
- Add a data binding to the Content property.
- Choose Project > Context > Timestamp as the data source.
- Use the Format Date function to set the date display format.
- Select the desired formatting settings.
By using this approach, you can display the current date in your PandaSuite application according to the specified format.
Creating a condition based on date/time
It is often necessary to create conditions based on the current time in an application. For example, you may want to display a different message depending on the time of day. To achieve this in PandaSuite, you can use conditional actions based on the Timestamp data.
To display a message based on the time, follow these steps:
- Prepare all the messages in a Multi-state component.
- Add a condition that uses Project > Context > Timestamp as the data source.
- Use the Format Date function to customize the format and the H code to return the hour as a number from 0 to 23 when using a 24-hour clock.
- Use the Parse Number function to parse the string with a number and return the number.
- Finalize the condition by adding a lower and upper value.
- Add the action: Interact with a component > Multi-state > Change state.
- Repeat the same steps for the other messages.
Formatting the Timestamp Data with the Format Date Function
To format the Timestamp data according to a desired format, you can use the Format Date function in PandaSuite. This function allows you to customize the appearance of the date and time by using specific parameters.
The first step is to choose the Type between Predefined or Custom.
Predefined
Here are the available parameters for the Predefined type:
- Date style : you have the choice between None, Short, Medium, Long, Full
Here is an example with the date of September 16, 2021, at 4:53 PM:
None | The date is not displayed |
Short | 9/16/21 |
Medium | Sep 16, 2021 |
Long | September 16, 2021 |
Full | Thursday September 16, 2021 |
- Time style: you have the choice between None, Short, Medium, Long, Full
Here is an example with the date of September 16, 2021, at 4:53 PM:
None | The time is not displayed |
Short | 4:53 PM |
Medium | 4:53:15 PM |
Long | 4:53:15 PM GMT+2 |
Full | 4:53:15 PM Central European Time |
- Time zone: choose the reference time zone
Custom
Here are the available parameters for the Custom type:
- Date/Time format: you can choose a custom format by using the universal codes for the Timestamp data.
Here are some commonly used codes:
yyyy | 4-digit year (e.g., 2023) |
MM | 2-digit month (e.g., 07 for July) |
dd | 2-digit day (e.g., 07) |
HH | 2-digit hour in 24-hour format |
hh | 2-digit hour in 12-hour format |
mm | 2-digit minute |
tt | A.M. or P.M. in two letters |
To find all the codes: Format Date / Time (Unicode)
- Time zone: choose the reference time zone
💡 Note: When editing in PandaSuite Studio, these data will be displayed based on the current language of the project. If you want to enforce a language, add a default language.