加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C# – 格式化当前时间

发布时间:2020-12-15 06:45:02 所属栏目:百科 来源:网络整理
导读:在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
在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到最后

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读