如何在 C# 中将 DateTime 转换为 yyyy-mm-ddT00:00:00.000Z 格式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19642975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 15:30:20 来源:igfitidea点击:
How do I convert DateTime to yyyy-mm-ddT00:00:00.000Z format in C#?
提问by wayfare
I want to convert dateTime to the above given format. I tried to look the docs but didnt find much information.
我想将 dateTime 转换为上述给定的格式。我试图查看文档,但没有找到太多信息。
采纳答案by Habib
Just pass the format "yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'"
to ToString
只需将格式传递"yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'"
给ToString
string str = DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'");
回答by Manish Vadher
If your DateTime Object is Nullable then use this
如果您的 DateTime 对象为 Nullable,则使用它
string str = DateTime.Now.Value.ToString("yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'");