Custom DateTime format

2019-08-12 13:41发布

What's the DateTime format "2011-09-12T10:28:55Z"? How can I get it using ToString()? I didn't get any information in Microsoft's documents about it. Nothing similar like this.

1条回答
Juvenile、少年°
2楼-- · 2019-08-12 14:24

You can get that using ToString with:

var text = date.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'",
                         CultureInfo.InvariantCulture);

I don't believe there's a standard date/time format which covers this, unfortunately.

Of course, if it's not already a UTC date/time then it'll be lying (that's what the 'Z' bit means). You can call DateTime.ToUniversalTime() to convert it, of course.

查看更多
登录 后发表回答