Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 1ccb66d

Browse files
committed
Update README.md
1 parent ea9d6e2 commit 1ccb66d

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,53 @@ JsonSerializer also supports serialization of anonymous types in much the same w
358358

359359
{"A":1,"B":2,"C":3,"D":4}
360360

361+
### Parsing JSON Dates
362+
363+
The default WCF Date that's returned in ServiceStack.Text can be converted with:
364+
365+
```js
366+
function todate (s) {
367+
return new Date(parseFloat(/Date\(([^)]+)\)/.exec(s)[1]));
368+
};
369+
```
370+
371+
Which if you're using the [servicestack-client](https://docs.servicestack.net/servicestack-client-umd) npm package can be resolved with:
372+
373+
```ts
374+
import { todate } from "servicestack-client";
375+
var date = todate(wcfDateString);
376+
```
377+
378+
Or if using [ss-utils.js](https://docs.servicestack.net/ss-utils-js) that's built into ServiceStack:
379+
380+
```js
381+
var date = $.ss.todate(wcfDateString);
382+
```
383+
384+
If you change ServiceStack.Text default serialization of Date to either use the ISO8601 date format:
385+
386+
```csharp
387+
JsConfig.DateHandler = DateHandler.ISO8601;
388+
```
389+
390+
It can be parsed natively with:
391+
392+
```js
393+
new Date(dateString)
394+
```
395+
396+
Likewise when configured to return:
397+
398+
```csharp
399+
JsConfig.DateHandler = DateHandler.UnixTimeMs;
400+
```
401+
402+
It can also be converted natively with:
403+
404+
```js
405+
new Date(unixTimeMs)
406+
```
407+
361408
## Global Default JSON Configuration
362409

363410
The JSON/JSV and CSV serialization can be customized globally by configuring the `JsConfig` or type-specific `JsConfig<T>` static classes with your preferred defaults. Global static configuration can be configured once on **Startup** using `JsConfig.Init()`, e.g:

0 commit comments

Comments
 (0)