微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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到最后

原文地址:https://www.jb51.cc/csharp/94778.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐