Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert serialized C# DateTime to JS Date object

How can I convert that date format /Date(1302589032000+0400)/ to JS Date object?

like image 342
Neir0 Avatar asked Aug 03 '11 14:08

Neir0


People also ask

What is serialization C?

Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.

What does Jsonconvert Deserializeobject do?

Deserializes the JSON to the specified . NET type. Deserializes the JSON to the specified . NET type using a collection of JsonConverter.

What is Jsonconvert SerializeObject C#?

SerializeObject Method (Object, Type, JsonSerializerSettings) Serializes the specified object to a JSON string using a type, formatting and JsonSerializerSettings. Namespace: Newtonsoft.Json.

What is ISerializable C#?

The ISerializable interface implies a constructor with the signature constructor (SerializationInfo information, StreamingContext context) . At deserialization time, the current constructor is called only after the data in the SerializationInfo has been deserialized by the formatter.


1 Answers

Remove the text first:

var src = "/Date(1302589032000+0400)/";

//Remove all non-numeric (except the plus)
src = src.replace(/[^0-9 +]/g, ''); 

//Create date
var myDate = new Date(parseInt(src));

Here's a workding jsFiddle

like image 109
James Hill Avatar answered Sep 21 '22 22:09

James Hill