Format a Time String like "HH:MM:SS". Here is my solution

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Format a Time String like "HH:MM:SS". Here is my solution

Postby arjfca » 07 Mar 2012

Can't say if there is a leaner solution to format like "HH:mm:ss" a string that represent the ending time of a bar

Here is a function called "TimeString" that I create to do it

StringTime = Timestring(153705); Result = "15:37:05)
// Time_S = (153705)

Code: Select all

//TimeString, return a string formated "HH:MM:SS"

Input: Time_in (Numeric);

Var: TimeLen (0);
Var: TimeStr ("");
Var:TST (""); // Time String Temp

TST = NumToStr(Time_IN,0);
TimeLen = StrLen(NumtoStr(Time_IN,0));

Switch TimeLen begin
Case = 0:
TimeStr = "00:00:00";
Case = 1:
Timestr = "00:00:0" + tst;
Case = 2:
Timestr = "00:00:" + tst;
Case = 3:
TimeStr = "00:0" + midstr(tst,1,1) + ":" + midstr(tst,2,2);
case = 4:
Timestr = "00:" + midstr(tst,1,2) + ":" + midstr(tst,3,2);
case = 5:
Timestr = "0" + midstr(tst,1,1) + ":" + midstr(tst,2,2) + ":" + midstr(tst,4,2);
case = 6:
Timestr = Midstr(tst,1,2) + ":" + midstr(tst,3,2) + ":" + midstr(tst,5,2);
end;

TimeString = TimeStr;
Martin

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Format a Time String like "HH:MM:SS". Here is my soluti

Postby JoshM » 07 Mar 2012

Can't say if there is a leaner solution to format like "HH:mm:ss" a string that represent the ending time of a bar

Code: Select all

Print(FormatTime("HH:mm:ss", ELTimeToELTime_s(Time_s)));
Sorry :| (But I hope I misunderstood you :) )

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Format a Time String like "HH:MM:SS". Here is my soluti

Postby arjfca » 07 Mar 2012

No offense John :)

I did post my solution with the taught in the background that a clever solution exist. I even did a chat session with MC this afternoon and after 30 min, they told me that is was not possible to do it directly and suggest me to report for a new function.

Have a great day

Martin

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Format a Time String like "HH:MM:SS". Here is my soluti

Postby arjfca » 07 Mar 2012

Can't say if there is a leaner solution to format like "HH:mm:ss" a string that represent the ending time of a bar

Code: Select all

Print(FormatTime("HH:mm:ss", ELTimeToELTime_s(Time_s)));
Sorry :| (But I hope I misunderstood you :) )
John, a little error in your code. ELTimetoDATEtime_s

Code: Select all

Print FormatTime("HH:mm:ss", ELTimetodatetime_s(Time_s));

FormatTime("HH:mm:ss", ELTimetodatetime_s(Time_s))); // = 20:10:25

Obviously yours is leaner

Martin

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: Format a Time String like "HH:MM:SS". Here is my soluti

Postby arjfca » 07 Mar 2012

Can't say if there is a leaner solution to format like "HH:mm:ss" a string that represent the ending time of a bar

Code: Select all

Print(FormatTime("HH:mm:ss", ELTimeToELTime_s(Time_s)));
Sorry :| (But I hope I misunderstood you :) )
John, a little error in your code. ELTimetoDATEtime_s

Code: Select all

Print FormatTime("HH:mm:ss", ELTimetodatetime_s(Time_s));

FormatTime("HH:mm:ss", ELTimetodatetime_s(Time_s))); // = 20:10:25

Obviously yours is leaner

Martin


Return to “User Contributed Studies and Indicator Library”