如何获得当前时间(而不是日期和时间)?

例如:下午5:42:12


当前回答

获取当前日期和时间,然后只使用它的时间部分。看看MSDN文档中格式化日期时间字符串的可能性。

其他回答

Datetime。TimeOfDay返回一个TimeSpan,可能就是你要找的。

计算当前的datetime:

DateTime theDate = DateTime.UtcNow;

string custom = theDate.ToString("d");

MessageBox.Show(custom);

非常简单的datetime,现在。ToString(“hh: mm: ss tt”)

获取当前日期和时间,然后只使用它的时间部分。看看MSDN文档中格式化日期时间字符串的可能性。

这是一个可能的解决方案:

DateTime now = DateTime.Now;
string time = now.ToString("T");