-3

Here I am trying to dispaly current system date and time in a format August 19, 2017 6:58 PM in Asp.net MVC view.
But instead of that I get 8/19/2017 7:07:29 PM.How am I suppose to get the first format.

Below is my code:

<span class="description">
  Shared publicly -  @DateTime.Now              
</span>
CrossWords
  • 47
  • 3
  • 9
  • Have a read of https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings and https://stackoverflow.com/a/24728080/34092 – mjwills Aug 19 '17 at 13:37
  • _@DateTime.Now.ToString("MMMM d, yyyy h:mm tt", CultureInfo.InvariantCulture);_ please study [Custom Format Date and Time Format Strings](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings) – Steve Aug 19 '17 at 13:38

2 Answers2

0

If you want an explicit format, you can do this:

<span class="description">
  Shared publicly -  @DateTime.Now.ToString("MMMM d, yyyy h:mm tt")
</span>
Tim
  • 5,940
  • 1
  • 12
  • 18
0

You can try this way

@{
    string formatted = @DateTime.Now.ToString("dd-MM-yyyy");
}

<span class="description">
    Shared publicly -  @formatted              
</span>

Here is a good reference for different formats.