how can I convert "/Date(1479250800000)/" String to a C# Datetime?
Thanks in advance
how can I convert "/Date(1479250800000)/" String to a C# Datetime?
Thanks in advance
Assuming the value inside the brackets is number of ticks:
var datstr = "/Date(1479250800000)/";
long ticks = Convert.ToInt64(datstr.Substring(6, 13));
DateTime date = new DateTime(ticks);
There will be a difference between .Net and javascript tick value:
The JavaScript Date type's origin is the Unix epoch: midnight on 1 January 1970. The .NET DateTime type's origin is midnight on 1 January 0001. If by "ticks" you mean something like "milliseconds since the epoch", you can call ".getTime()
There are 621355968000000000 epoch ticks for javascript from Ist Jan 1900 to Ist Jan 1970. And here 10000 are the ticks per milliseconds.
quoted from here. You will need to correct for this. the last line would look like the following:
DateTime date = new DateTime(ticks * 10000 + 621355968000000000);
You'll get the string "/Date(1479250800000)/" as a date value in javascript if you are sending it from C#. But if you sending back the value to a date field in C# then the value will be deserialized as DateTime value. You don't need to convert it explicitly, just get it in a DateTime field.