How do I get the current time of day in datetime format?
You can use DateTime.TimeOfDay:
TimeSpan currentTime = DateTime.Now.TimeOfDay;
This will retrieve this as a TimeSpan. If you want this in a "DateTime" format, just use DateTime.Now
(realizing, of course, that this also includes the date).
You can use DateTime.Now for that. Example:
$ cat Test.cs
using System;
namespace Test
{
public class TestClass
{
public static void Main(string[] args)
{
DateTime example = DateTime.Now;
Console.WriteLine(example);
}
}
}
$ gmcs *.cs
$ mono Test.exe
2/18/2011 11:03:13 PM
精彩评论