C# – 格式化当前时间

在C#中,如何以下列格式获取当前的DateTime? 2011-08-10T21:36:01.6327538Z

解决方法

DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ")

请记住,DateTime.Now有时只精确到千分之一秒,具体取决于系统时钟. This page显示如下:

It is possible to display very small fractional units of a second,such as ten thousandths of a second or hundred-thousandths of a second. However,these values may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later,and Windows Vista operating systems,the clock’s resolution is approximately 10-15 milliseconds.

但是,如果您自己填充DateTime,可以使其更准确.我不知道任何其他内置的库比DateTime.UtcNow更精确.

此外,DateTime.UtcNow.ToString(“o”)将为您提供一个序列日期时间字符串.这并没有指定最后的时区,所以如果你正在处理Utc,你仍然需要添加Z到最后

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...