Is anyone familiar with this format and how to convert it?
The string "/Date(1427982649000-0400)/" appears to be a time value in milliseconds followed by an offset in the ±HHmm format. To convert this to a Date, adjust the time value based on the offset.
If we assume the usual sign convention for offsets, then subtracting a positive offset and adding a negative one will yield the correct UTC value. A code snippet like the following should work:
var s = '/Date(1427982649000-0400)/';
// Extract numerical values
var b = s.match(/\d+/g);
// Determine the sign of the offset
var sign = /-/.test(s)? -1 : +1;
// Adjust the time value by converting the offset to milliseconds
// and use it to create a Date object
var ms = +b[0] + sign * (b[1].slice(0,2)*3.6e6 + b[1].slice(-2)*6e4);
console.log(new Date(ms).toISOString()); // 2015-04-02T17:50:49.000Z
In the given example, "2015-04-02 09:50:49.000" does not specify a timezone, meaning it represents different moments across various timezones. If the database stores this value as is, assuming the missing timezone is UTC-0800 would be logical. Storing values in UTC along with the offset is recommended to avoid ambiguity related to host timezones.
The complexity arises from ECMAScript's timezone offset convention being opposite to the standard, where west of Greenwich has positive offsets and east has negative. Therefore, applying this convention, "/Date(1427982649000-0400)/" translates to 2015-04-02T09:50:49.000Z, which may align with your requirements.
If that's the case, simply modify the line:
var sign = /-/.test(s)? -1 : +1;
to
var sign = /-/.test(s)? +1 : -1;