SS is returning a string property for a date field - ‘/Date(1606208773433)/’, do I have to do extra parsing in JS to get the value of the date in order for me to use it?
This answer contains info on parsing JSON dates:
The default WCF Date that’s returned in ServiceStack.Text can be converted with:
function todate (s) {
return new Date(parseFloat(/Date\(([^)]+)\)/.exec(s)[1]));
};
Which if you’re using the servicestack-client npm package can be resolved with:
import { todate } from "servicestack-client";
var date = todate(wcfDateString);
Or if using ss-utils.js that’s built into ServiceStack:
var date = $.ss.todate(wcfDateString);
If you change ServiceStack.Text default serialization of Date to either use the ISO8601 date format:
JsConfig.DateHandler = DateHandler.ISO8601;
It can be parsed natively with:
new Date(dateString)
Likewise when configured to return:
JsConfig.DateHandler = DateHandler.UnixTimeMs;
It can also be converted natively with:
new Date(unixTimeMs)
1 Like