stTime t = getTime();
sprintf(text, "%02d:%02d:%02d %s", t.hour%12, t.min, t.sec, (t.hour>11 ? "PM" : "AM"));
Game A Gogo wrote:at one point in the scripts, you have this part of code sprintf(text, "%d:%d:%d AM", Hour, u.min, u.sec);
as you can see the %d is to display a double value (Hence the d), you could also use i (I'd recommend it) for integer values "%i"
But how to add padding zeros? easy like eating a pie you like! sprintf comes with more formatting options, replace the "%d" to "%02i", the 0 indicates that it should pad with 0's (If you leave it out, it will pad with spaces) and the 2 indicates how many digits you want to appear minimum.
So...
%02i could give out: "04"
%2i could give out: " 4"
%04i could give out: "0004"
Wertyboy wrote:Game A Gogo wrote:at one point in the scripts, you have this part of code sprintf(text, "%d:%d:%d AM", Hour, u.min, u.sec);
as you can see the %d is to display a double value (Hence the d), you could also use i (I'd recommend it) for integer values "%i"
But how to add padding zeros? easy like eating a pie you like! sprintf comes with more formatting options, replace the "%d" to "%02i", the 0 indicates that it should pad with 0's (If you leave it out, it will pad with spaces) and the 2 indicates how many digits you want to appear minimum.
So...
%02i could give out: "04"
%2i could give out: " 4"
%04i could give out: "0004"
thx, so what about when 01:00 PM, i want it to: 13:00 (Removed AM & PM)
Users browsing this forum: No registered users and 1 guest