C#timespan,分钟和秒 [英] C# timespan with minutes and secconds

查看:588
本文介绍了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


这篇关于C#timespan,分钟和秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆