Monthly Archives: June 2010

Monthly Archives: June 2010

How to convert a JSON date serialized by an ASMX web service to a JavaScript Date object

Posted on by Joe in Ajax, ASP.NET, JavaScript | 5 Comments

JSON doesn’t have a standard way to represent a date. You can read about the reasons behind this here. If you are using an ASMX web service returning JSON then you’ll find it serializes the DateTime object to a string that looks like this: /Date(1278943200000)/ The numer in this string is the number of milliseconds since January 1st 1970 UTC, and this number can be used as a constructor argument to the JavaScript Date object.  So all we need to …

How to get the time difference between two DateTimes using C#

Posted on by Joe in C# | Leave a comment

Here’s a quick an easy way to show the time difference between two DateTime objects using C#. The DateTime structure has an overridden subtract operator which return a TimeSpan object when subtracting two DateTimes: You can then use this TimeSpan to get the amount of time between each DateTime: In the above example I’m comparing a date in the past to the current date. This could be useful for working out the total amount of time that has passed since …

Convert a comma separated string of numbers to an integer array using C#

Posted on by Joe in C#, Linq | 1 Comment

Today I needed to convert a comma separated string of numbers in an integer array. Here is how you can do it in one line using Linq: