Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, i need help with TimeSpan because this is showing HH:MM:SS and i just want it to show MM:SS not the Hours

What I have tried:

second++;
TimeSpan unlimited_timer = new TimeSpan(0, 0, second);
TimerTime = unlimited_timer.ToString();


my second = 0
Posted
Updated 22-Jun-16 13:42pm

This is a simple code that handles your problem
C#
DateTime d1 = new DateTime(1999, 5, 4, 12, 45, 33, 50);
DateTime d2 = new DateTime(1999, 5, 4, 12, 48, 38, 50);

TimeSpan ts = d2 - d1;

MessageBox.Show(ts.ToString("mm\\:ss"));
 
Share this answer
 
 
Share this answer
 
Please see:
TimeSpan.ToString Method (String) (System),
TimeSpan.ToString Method (String, IFormatProvider) (System),
Standard TimeSpan Format Strings,
Custom TimeSpan Format Strings.

The structure System.TimeSpan itself has no any format; its representation has nothing to do with strings; strings representation only appears in formatting and parsing methods.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900