ISO Display

ISO Display

ISO Display C# Web Control Code

Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (item == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
//using : for colon and ? for question mark and   for space
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

string rawIsoDate = Sitecore.DateUtil.IsoNowDate;
if (!string.IsNullOrEmpty(rawIsoDate))
{
    output.Write("{0}&#58;&#160;{1}", "Raw ISO Date from DateUtil.IsoNowDate", "<b>" + rawIsoDate + "</b><br/>");

    string isIsoDate1 = Sitecore.DateUtil.IsIsoDate(rawIsoDate).ToString();
    if (!string.IsNullOrEmpty(isIsoDate1))
    {
        output.Write("{0}&#63;&#160;{1}", "Is ISO Date", "<b>" + isIsoDate1 + "</b><br/>");
    }
    
    string formattedIsoDate1 = Sitecore.DateUtil.FormatIsoDate(rawIsoDate);
    if (!string.IsNullOrEmpty(formattedIsoDate1))
    {
        output.Write("{0}&#58;&#160;{1}", "Formatted ISO Date", "<b>" + formattedIsoDate1 + "</b><br/>");
    }

}

output.Write("<hr />");
string toIsoDate = Sitecore.DateUtil.ToIsoDate(System.DateTime.Now);
if (!string.IsNullOrEmpty(toIsoDate))
{
    output.Write("{0}&#58;&#160;{1}", "Raw ISO Date from DateUtil.ToIsoDate()", "<b>" + toIsoDate + "</b><br/>");

    string isIsoDate2 = Sitecore.DateUtil.IsIsoDate(toIsoDate).ToString();
    if (!string.IsNullOrEmpty(isIsoDate2))
    {
        output.Write("{0}&#63;&#160;{1}", "Is ISO Date", "<b>" + isIsoDate2 + "</b><br/>");
    }

    string formattedIsoDate2 = Sitecore.DateUtil.FormatIsoDate(toIsoDate);
    if (!string.IsNullOrEmpty(formattedIsoDate2))
    {
        output.Write("{0}&#58;&#160;{1}", "Formatted ISO Date", "<b>" + formattedIsoDate2 + "</b><br/>");
    }

}     

output.Write("<hr />");
string rawIsoNow = Sitecore.DateUtil.IsoNow;
if (!string.IsNullOrEmpty(rawIsoNow))
{
    output.Write("{0}&#58;&#160;{1}", "Raw ISO Date from DateUtil.IsoNow", "<b>" + rawIsoNow + "</b><br/>");

    string isIsoNow = Sitecore.DateUtil.IsIsoDate(rawIsoNow).ToString();
    if (!string.IsNullOrEmpty(isIsoNow))
    {
        output.Write("{0}&#63;&#160;{1}", "Is ISO Date", "<b>" + isIsoNow + "</b><br/>");
    }

    string formattedIsoNow = Sitecore.DateUtil.FormatIsoDate(rawIsoNow);
    if (!string.IsNullOrEmpty(formattedIsoNow))
    {
        output.Write("{0}&#58;&#160;{1}", "Formatted ISO Date", "<b>" + formattedIsoNow + "</b><br/>");
    }

}
output.Write("<hr />");

string rawIsoTime = Sitecore.DateUtil.IsoNowTime;
if (!string.IsNullOrEmpty(rawIsoTime))
    output.Write("{0}&#58;&#160;{1}", "Raw ISO Time from DateUtil.IsoNowTime", "<b>" + rawIsoTime + "</b><br/>");

string toIsoTime = Sitecore.DateUtil.ToIsoTime(System.DateTime.Now);
if (!string.IsNullOrEmpty(toIsoTime))
    output.Write("{0}&#58;&#160;{1}", "Raw ISO Time from DateUtil.ToIsoTime()", "<b>" + toIsoTime + "</b>");

output.RenderEndTag(); //Div


C# Web Control Real-time Output

Item: ISO Display

Raw ISO Date from DateUtil.IsoNowDate: 20141006
Is ISO Date? False
Formatted ISO Date: Monday, October 06, 2014 12:00 AM

Raw ISO Date from DateUtil.ToIsoDate(): 20141006T081335
Is ISO Date? True
Formatted ISO Date: Monday, October 06, 2014 8:13 AM

 

Raw ISO Date from DateUtil.IsoNow: 20141006T081335
Is ISO Date? True
Formatted ISO Date: Monday, October 06, 2014 8:13 AM


Raw ISO Time from DateUtil.IsoNowTime: 081335

Raw ISO Time from DateUtil.ToIsoTime(): 081335

Notes

  • System Date and Time functions will reflect time zone of server