C#timespan,分钟和秒

问题描述:

您好,我需要TimeSpan的帮助,因为这显示HH:MM:SS,我只想让它显示MM:SS不是时间



我尝试过:



秒++;

TimeSpan unlimited_timer = new TimeSpan(0,0,秒);

TimerTime = unlimited_timer.ToString();





我的第二个= 0

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

这是一个处理问题的简单代码

This is a simple code that handles your problem
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"));


请参阅 TimeSpan.ToString Method() [ ^ ]


请参阅:

TimeSpan.ToString方法(字符串)(系统)

TimeSpan.ToString方法(字符串,IFormatProvider)(系统)

标准TimeSpan格式字符串

卡斯特om TimeSpan格式字符串



结构 System.TimeSpan 本身没有任何格式;它的表示与字符串无关;字符串表示只出现在格式化和解析方法中。



-SA
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