开发者

How do you get the current time of day in datetime format? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_高级运维 Closed 10 years ago.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜