dotnet-json-date
Version:
parse and stringify .net JSON dates
62 lines (41 loc) • 1.25 kB
Markdown
and stringify .Net JSON dates.
```sh
npm install dotnet-json-date
```
```js
var dotnetJsonDate = require('dotnet-json-date');
```
```js
var date = dotnetJsonDate.parse('/Date(1466121600000)/')
date == new Date(1466121600000);
```
```js
var string = dotnetJsonDate.stringify(new Date(1466121600000))
string == '/Date(1466121600000)/';
```
Stringify all dates to .Net JSON dates when stringifying JSON
```js
var object = {
name: 'bob',
birthday: new Date(1466121600000),
numberOfEyes: 3
};
var json = JSON.stringify(object, dotnetJsonDate.replacer);
json == '{"name":"bob","birthday":"/Date(1466121600000)/","numberOfEyes":3}';
```
Parse all .Net JSON dates when parsing JSON
```js
var json = '{"name":"bob","birthday":"/Date(1466121600000)/","numberOfEyes":3}';
var object = JSON.parse(json, dotnetJsonDate.reviver);
object == {
name: 'bob',
birthday: new Date(1466121600000),
numberOfEyes: 3
};
```
Parse