Hi I use some code for showing the current and past time when my EA performs an action or event.
It converts the time from a MqlDateTime variable to a string variable with this format: "HH:MM"
When the hour or minute is before 10, it adds an extra "0" to the string, see the code:
Info.sTimePeriod // = struct for storing the time in a string format.MqlDateTime TimePeriod; // MQL date/time structure // Convert current PC time to MQL time format. TimeLocal(TimePeriod);
// Stringvalue for time expression in standard time method.if(TimePeriod.hour < 10)
{
Info.sTimePeriod = (string)0 + (string)TimePeriod.hour;
}
else
{
Info.sTimePeriod = (string)TimePeriod.hour;
}
Info.sTimePeriod = Info.sTimePeriod + ":";
if(MathRound(dMinTime_Period) < 10)
{
Info.sTimePeriod = Info.sTimePeriod + (string)0 + (string)MathRound(dMinTime_Period);
}
else
{
Info.sTimePeriod = Info.sTimePeriod + (string)MathRound(dMinTime_Period);
}
Although this code works. Its is very clumsy and I think that it can be done more simple by using the StringFormat() function but I don't know how to use this function.
Hi I use some code for showing the current and past time when my EA performs an action or event.
It converts the time from a MqlDateTime variable to a string variable with this format: "HH:MM"
When the hour or minute is before 10, it adds an extra "0" to the string, see the code:
Although this code works. Its is very clumsy and I think that it can be done more simple by using the StringFormat() function but I don't know how to use this function.
https://www.mql5.com/en/docs/convert/stringformat
Can anybody help me?
Thanks.