String Format , only show minutes & seconds?

yogi_bear_79

Member
Joined
Sep 30, 2009
Messages
19
Programming Experience
Beginner
I am using the following code to display a timer. I have no use for the hours, is it possible to format the string to show only MM:SS?

VB.NET:
Me.lblTime.Text = String.Format("{0}:{1:d2}:{2:d2}", remainingTime.Hours, remainingTime.Minutes, remainingTime.Seconds)
 
i havent worked too much with string.format but if its formated in 00:00:00 then just split the string by ":" and display the first and second index
VB.NET:
Dim StringSplit() as string = split(StringToSplit,":")
lbltime.text = stringsplit(1) & ":" & stringsplit(2)

that would be the basics of it. let me know if you run into any problems
 
If your TimeSpan will always be less than 1 hour then you can just drop the hours from what you've already got:
VB.NET:
Me.lblTime.Text = String.Format("{0:d2}:{1:d2}", remainingTime.Minutes, remainingTime.Seconds)
If you want to show minutes over 59 then you would have to do this:
VB.NET:
Me.lblTime.Text = String.Format("{0:d2}:{1:d2}", Math.Truncate(remainingTime.TotalMinutes), remainingTime.Seconds)
 
Last edited:
No need to show off jmchilhinney xP jkjk. ive used string.format like once so i didnt really know much about it. You're way is surely better. I tried though :p
 
Well, you could use this:

VB.NET:
DateTime.Now.ToString("mmss")

Hope that helped :)
I don't think that's an option because I think remainingTime is a TimeSpan, not a DateTime.
 
Back
Top