Created
October 27, 2017 08:06
-
-
Save ps-team/93a841a20eeb7f8f2639c037ca3fb580 to your computer and use it in GitHub Desktop.
DateTime formatting. For different formatting options please refer to the MDN docs: https://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment