LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read date and time from .txt file and display them on the Graph ?

Hi !

I want to read datas ,including date and time  from the .txt file,and then use PlotXY to plot them on the Graph. Date and time are the X-axis . 

The following is the part of code about handling time.

Scan(buf, "%d[x]%d[x]%d[x]%d[x]%d[x]%d[x]%d",
                   &ti.tm_year,&ti.tm_mon, &ti.tm_mday, &ti.tm_hour, &ti.tm_min, &ti.tm_sec, &w[cnt]);
  // Adjust fields for tm struct correct format
  ti.tm_mon--; ti.tm_year -= 1900;
  ti.tm_hour += 9; 
  // Calculate timestamp
  et[cnt] = mktime (&ti);

 

 

Year、month、day、minute and second are shown right.But,the"Hour" is incorrect.I think it maybe jet lag.As we are in China,we use UTC+8.So I make "ti.tm_hour += 8;"

it shows right in my computer,but it must make "ti.tm_hour += 9;" that could be shown right in the target computer.I could not find the reason. Where is my mistake ?

2011-11-28 15:08:53  246 

2011-11-28 15:08:54  246  
2011-11-28 15:09:04  246
......

 

2011-12-01 10:15:00  246  

2011-12-01 10:15:04  246  

When I did not handle "ti.tm_hour ",the Graph is :11.jpg

When I make "ti.tm_hour += 8",the Graph is :22.jpg and this is right in  my computer.

When I make "ti.tm_hour += 9;",the Graph is :333.jpg It would be right in the other computer if I make "ti.tm_hour += 9;".

Is there anyone could tell me how to modify it ?

Thank you very much !

 

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
0 Kudos
Message 1 of 6
(3,546 Views)

A 1-hour time shift could depend on Daylight Saving Time applied on a system but not on another. Are you in DST period now? And could one computer have automatic DST adjustment on and the other off?

Also, it appears that data are collected using GetSystemTime () function. If you can modify the originating program, using GetLocalTime () instead you should get the correct time based on your time zone.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 6
(3,542 Views)

Hi !

Thank you very much for your reply.

We are not in DST period now.How could I judge whether a computer has automatic DST adjustment on or off ?

 

I've tried that  the following two functions  all could get the correct date and time when saving datas.

GetCurrentDateTime (&currDateTime);

 

strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", localtime(&t)); 

 But,they could not be read and shown correctly on the Graph.Besides,I could not find the GetSystemTime () function in my CVI software.(My CVI version is 2009SP1)

lo.jpg

Looking forward to your advice.

Thank you very much.

Best regards.

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
0 Kudos
Message 3 of 6
(3,537 Views)

CVI comes with a help: entering GetSystemTime in the Search Tab yields the following page which also tells the library where the function is located: in this case it is the utility library:

 

help.jpg

 

 

0 Kudos
Message 4 of 6
(3,534 Views)

Hi!

Thank you very much for your reply.

I'm sorry that I made a mistake.That is not GetSystemTime () funtion  but GetLocalTime function that I could not find.

lo.jpg

 

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
0 Kudos
Message 5 of 6
(3,531 Views)

GetLocalTime is part of Win32 APIs, together with a GetSystemTime function that has the same name of the corresponding function in the utility library. Both functions make use of a SYSTEMTIME structure to hold date and time informations. You will need to add windows.h to your project in order to use them.

 

I am using GetLocalTime function together with MakeDateTime in the User interface library to obtain the time information to pass to the graphs. I never really payed attention to time informations but I guess if a 1-hour shift do exist some of my customers will have informed us.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 6
(3,527 Views)