LabVIEW programming: Converting time stamp to string

Publisher:science56Latest update time:2014-11-04 Source: ck365Keywords:LABVIEW Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The time stamp is a special numeric control that does not exist in earlier versions of Labview , but may appear after 8.X. This special type of numeric control contains all the time and date information we need.

In the Timing Function palette, LABVIEW provides many time-related functions, including functions for converting time and date to strings. In fact, the Format Write String function fully supports time tags, and its conversion functions are more extensive and comprehensive.

Similar to converting numbers to strings, the key to converting time stamps to strings is also to format the string. LabVIEW provides many special time-related time format codes . These format characters can not only be used to convert to strings, but also to display them in time stamp controls. The following example will use both string and time stamp display controls to display the time and date we need.

1. Get system time and date (year, month, day, hour, minute, second)

Getting the system time and date (year, month, day, hour, minute, second) is the most commonly used time operation. LABVIEW specifically provides a format time/date function that can directly get the current time and date without adding any time code. The default time code is %c.

The time in LABVIEW is divided into absolute time and relative time. Absolute time is simply what we call system time and date, and relative time can be used to represent elapsed time, such as the difference between two absolute times (system times).

The time format code for absolute time is %<>T, which is the container of the time format code. Other format codes should be located in <>.

The time format code %c displays the date and time according to the format specified by the local computer language.

 

For the time label display control, its time and date display format is generally set through the property dialog box. In order to illustrate the time format code, I used the property node setting.

2. Get the time and date strings separately

Often, we need to obtain the time or date separately. LABVIEW provides a special function to obtain the date/time string. This function returns two strings, representing the time and date respectively. See the figure below for specific usage.

The formatted string function can also be used to obtain time and date, and you can define the display format yourself, such as the separators between year, month, and day and their display order, as well as the hours, minutes, and seconds.

1. Get the date (year, month, day)

The time format code for the year is: %y for two-digit year (such as 97), %Y for four-digit year (such as 1997). The time format code for the month is: %m. The time format code for the day is: %d

2. Get time (hour, minute, second)

There are two time format codes: 24-hour system --- %H, 12-hour system --- %I;

The time format code for minutes is: %M; (lowercase represents month)

The time format code for seconds is: %S.

3. Get year, month, day, hour, minute, and second arbitrarily

Through the time format codes of year, month, day, hour, minute and second, we can get any one or several of them, which is very common in timed monitoring or timed data recording.

The following example uses the Format Write To String function to perform an operation once per minute, such as an alarm, writing to a file, etc. To ensure that the operation is performed only once per minute, the operation must be performed on the rising edge of the minute change.

4. Get the decimal (millisecond) number

This can also be achieved using the formatted write string function, as shown below:

5. Get information related to "week"

The time mark in LABVIEW contains all the information of the system time, and of course also includes several time format codes related to "week". In some European joint ventures, weeks are often used to represent working hours, such as today is the first week and the first day of the year, etc., which can be easily achieved using the time format codes related to the week.

The time format code %A represents the full name of the day of the week (such as Monday), and %a represents the abbreviated name of the day of the week (such as Monday).

For Chinese operating systems, %A and %a have exactly the same effect, but for English operating systems they are completely different.

The time format code %w returns the day of the week in decimal (0-6), where 0 represents Sunday.

The time format code %U returns the week number of the year (0-53), with Sunday as the first day.

The time format code %W returns the week number of the year (0-53), with Monday as the first day.

 

6. Relative Time

Absolute time generally refers to system time, which has a time of 0. In many cases, we do not care about the current absolute time. For example, basketball games, test program running time, etc., these are all "experienced" times, which are actually the difference between two absolute times. We call this time difference relative time.

Relative time is usually expressed as a double-precision number, indicating the number of seconds that have passed. For relative time, it may also be necessary to express it in days, hours, minutes, seconds, etc. For these needs, we do not need to calculate them ourselves, and relative time can be used for automatic conversion.

The time format code for relative time is: %t. %<> indicates a container for relative time.

文章内容结束
Keywords:LABVIEW Reference address:LabVIEW programming: Converting time stamp to string

Previous article:LabVIEW programming skills: copying conditional structures and event structures
Next article:LabVIEW Programming Tips - How to Implement Aggregate Functions

Latest Test Measurement Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号