timer to string

jeffcoll
2018-01-22
2018-01-24
  • jeffcoll - 2018-01-22

    Best,

    I have the following problem, I now have a timer, where I use the ET on a screen that I convert to a string, but unfortunately I see the following 24m30s490ms, is there a possibility to defend the 490ms defenitively,?

    Br
    Jeffrey Collewijn

     
  • Anonymous - 2018-01-23

    Originally created by: scott_cunningham

    You could check the OSCAT library - see CoDeSys store. Or, this is easy enough to roll your own. Here is one way:

    TOD is a nice format for this (TOD#hh:mm:ss.mmm). Basically convert TIME to TOD to STRING and trim it for the answer.

    FUNCTION CleanTime : STRING
    VAR_INPUT
    Β  Β TimeValue : TIME;
    END_VAR
    VAR
    Β  Β MyTOD : TOD;
    Β  Β MyStr : STRING[12]; //lose the milliseconds
    END_VAR
    MyTOD := TIME_TO_TOD(TimeValue);
    MyStr := TOD_TO_STRING(MyTOD);
    CleanTime := Standard.RIGHT(STR:=MyStr,8);
    

    So now, you can just do:

    Pretty := CleanTime(Timer.ET);
    
     
  • josepmariarams - 2018-01-24

    Or, you can do:

    a:time;

    a:=a/1000;

    and after

    a:=a *1000

    as a is an integer kind...

     

Log in to post a comment.