What is the date format of e.g. 2020-06-26T21:04:18.1823633Z called?

丶灬走出姿态 提交于 2020-07-09 12:46:08

问题


I’m using C# 4.6 to pass a datetime to a webservice that’s expecting it in a format like this: 2020-06-26T21:04:18.1823633Z, or yyyy-MM-ddTHH:mm:ss.fffffffZ.

On this website I’m finding formats that are similar (SortableDateTimePattern doesn’t have the Z and UniversalSortableDateTimePat­tern doesn’t have the T), but not identical. Is this a standard datetime format in C# and if not what would be the cleanest way to generate it?


回答1:


It is the standard ISO-8601 format https://en.wikipedia.org/wiki/ISO_8601

Most languages/libraries should be able to handle it as is, if not you may need to pluck the T or Z before processing.

You can format your date with:

MyDate.ToString("yyyy-MM-ddTHH:mm:ss.fffffffzzz");
//This will give you the time zone as say... -0400
//2018-06-27T10:08:03.123456-0400
//If you want it as Z (zulu) you can try
MyDate.ToString("o");
//2018-06-27T10:08:03.123456Z

You can see all the formatting options here



来源:https://stackoverflow.com/questions/51064670/what-is-the-date-format-of-e-g-2020-06-26t210418-1823633z-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!