Scroll to the bottom for the updated answer
This format (with T
in the middle and ending with Z
) is called by Sitecore ShortIsoDateTime
. I don't know if that is official name of it or not.
You can get it using Sitecore.DateUtil.GetShortIsoDateTime(dateTime)
method.
There are more formats which are used by Sitecore.
Sitecore.DateUtil
class is a really good place to learn more about them.
And there is a guide on Sitecore Docs: Date/time best practices
EDIT:
Z
character is added only if
if (datetime.Kind == DateTimeKind.Utc)
str += "Z";
EDIT 2:
Just run a test:
DateTime dateTime = DateTime.Now;
string string1 = Sitecore.DateUtil.GetShortIsoDateTime(dateTime);
// string1 is 20170310155908
dateTime = Sitecore.Common.DateTimeExtensions.SpecifyKind(dateTime, DateTimeKind.Utc);
string string2 = Sitecore.DateUtil.GetShortIsoDateTime(dateTime);
// string2 is 20170310155908Z
EDIT 3:
You are right. I was wrong since the beginning. The correct answer is: This format is called by Sitecore IsoDate
:
DateTime dateTime = DateTime.Now;
string dateTimeString1 = Sitecore.DateUtil.ToIsoDate(dateTime);
// dateTimeString1 == "20170310T162500"
dateTime = Sitecore.Common.DateTimeExtensions.SpecifyKind(dateTime, DateTimeKind.Utc);
string dateTimeString2 = Sitecore.DateUtil.ToIsoDate(dateTime);
// dateTimeString2 == "20170310T162500Z"