title: Convert date and time format string from moment.js to C# format
body: <p>Is there any existing function/library to convert date and time format from <code>moment.js</code> to <code>C#</code>?</p>
  
  <p>I will receive date and time format (only the format, without date and time value) from <code>moment.js</code> and need to display it in <code>C#</code>.</p>
  
  <p>For example:</p>
  
  <pre><code>YYYY-MM-DD h:mm A
  //this is the format received from moment.js
  </code></pre>
  
  <p>Then, if I have a <code>DateTime</code> in <code>C#</code>, I need to display it as</p>
  
  <pre><code>2018-06-14 2:30 PM
  //this is equivalent with YYYY-MM-dd h:mm tt
  </code></pre>
  
  <p>I need something like this:</p>
  
  <pre><code>string ConvertToCustomDateTimeFormat(string momentJsFormat){
     // should convert all moment.js date and time format to https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
  }
  </code></pre>
  
  <p>then I could use it like this:</p>
  
  <pre><code>string dateTimeFormat = ConvertToCustomDateTimeFormat("YYYY-MM-DD h:mm A");
  //dateTimeFormat value should be YYYY-MM-dd h:mm tt
  string formattedDateTime = myDateTime.ToString(dateTimeFormat);
  Console.WriteLine(formattedDateTime);
  // output will be 2018-06-14 2:30 PM
  </code></pre>