Parsing JSON DateTime from Newtonsoft’s JSON Serializer

Use one of the JsonConverters that come with Json.NET for working with dates to get a better format. JavaScriptDateTimeConverter will automatically give you a JavaScript date. public class LogEntry { public string Details { get; set; } public DateTime LogDate { get; set; } } [Test] public void WriteJsonDates() { LogEntry entry = new LogEntry … Read more

Twig date difference

Since PHP 5.3 There is another option without to write an extension. This example show how to calc the plural day/days {# endDate and startDate are strings or DateTime objects #} {% set difference = date(endDate).diff(date(startDate)) %} {% set leftDays = difference.days %} {% if leftDays == 1 %} 1 day {% else %} {{ … Read more

Get the complete month name in English

You can pass a CultureInfo object as an argument DateTime.ToString(): CultureInfo ci = new CultureInfo(“en-US”); var month = DateTime.Now.ToString(“MMMM”, ci); // alternatively you can use CultureInfo.InvariantCulture: var month = DateTime.Now.ToString(“MMMM”, CultureInfo.InvariantCulture);

Measure execution time in C#

The Stopwatch class is specifically designed to measure elapsed time and may (if available on your hardware) provide good granularity/accuracy using an underlying high-frequency hardware timer. So this seem the best choice. The IsHighResolution property can be used to determine whether high resolution timing is available. Per the documentation, this class offers a wrapper on … Read more