ps-team
10/27/2017 - 8:06 AM

DateTime formatting. For different formatting options please refer to the MDN docs: https://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

DateTime formatting. For different formatting options please refer to the MDN docs: https://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

@using Contensis.Framework.Web
@{
  // Variables
  var dateTime = Properties.time;
  var day = dateTime.ToString("d ").Replace(" ", "");  
  var dateTimeOne = dateTime.ToString("yyyy-MM-ddTHH:mm");  
  var dateTimeTwo = dateTime.ToString("dd") + DateSuffix(day) + dateTime.ToString(" MMMM yyyy");  
  
  // Format one
  <div>@dateTimeOne</div>

  // Format two
  <div>@dateTimeTwo</div>
}
@functions {
  public string DateSuffix(string date) {
    switch (date) {
      case "1":
      case "21":
      case "31":
        return "st";
      case "2":
      case "22":
        return "nd";
      case "3":
      case "23":
        return "rd";
      default:
        return "th";
    }
  }  
}