What could be the reason behind the varying outcomes browsers provide for the JavaScript expression new Date(-105998400000)?

When I use ASP.NET MVC 3 with the default Json serializer, I notice that dates from my JsonResults come back in the format /Date(-105998400000)/. To handle this, I extract the number and create a new Date object with this value. However, I am experiencing inconsistency between IE and Chrome.

var date = new Date(-105998400000);

You can check out my jsfiddle to see how different browsers display the results:

IE10 - Mon Aug 22 23:00:00 EST 1966
Firefox - Tue Aug 23 1966 00:00:00 GMT-0400 (US Eastern Standard Time)
Chrome - Tue Aug 23 1966 00:00:00 GMT-0400 (US Eastern Daylight Time)

Interestingly, two of my clients are seeing the August 22 date in Chrome.

I am puzzled by the fact that the same UTC milliseconds value returns different results in different browsers when creating a new Date object. Can you explain why this happens?

Answer №1

In my original solution to this problem, I opted to utilize ISO 8601 dates from the Json.NET serializer rather than UTC millisecond offsets from the outdated ASP.NET MVC3 Json serializer. You can find more details about my approach here.

I gained valuable insights into this issue thanks to user dandavis.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Transform or retrieve information from input into unformatted text

I'm working on a JavaScript function that can convert input values to text. However, I am facing an issue as I only want to convert data from one specific row into plain text. Each row in my table has 5 cells along with a button for saving the data. I ...

What is the reason that when the allowfullscreen attribute of an iframe is set, it doesn't appear to be retained?

Within my code, I am configuring the allowfullscreen attribute for an iframe enclosed in SkyLight, which is a npm module designed for modal views in react.js <SkyLight dialogStyles={myBigGreenDialog} hideOnOverlayClicked ref="simpleDialog"> <if ...

Utilize underscore's groupBy function to categorize and organize server data

I am currently utilizing Angular.js in conjunction with Underscore.js This is how my controller is structured: var facultyControllers = angular.module('facultyControllers', []); facultyControllers.controller('FacultyListCtrl', [' ...

Incorporating a node module into my Angularjs application

Recently, I stumbled upon a handful of modules that I would like to incorporate into my Angular app. However, I find myself at a crossroads on how to effectively integrate them into my project as I will need to use "require()" in my factory file. One part ...

Leveraging React hooks to combine an array and an object within an array

Struggling to incorporate an array and an object into another array. This is the setup in my constructor: const [dashboard, setDashboard] = useState({ loading: true, data: [], address: '' }) This is how I envision the final data structure: { ...

How can I convert a string number with leading zeros into a string in a node.js environment?

When rendering a page, I pass the id as a string (e.g. 001, 002) but at the client side, I receive it as a number (e.g. 1, 2). res.render('leafletDemo',{id:userID,latitude:latitude,longitude:longitude}); Is there a way to keep the id as a str ...

What is the best way to retrieve a specific property from a JSON object that is stored as an environment variable and use it within the

Here, I am saving the response object in an environment variable. let res = pm.response.json(); postman.setEnvironmentVariable('currentUser', JSON.stringify(res)); The 'res' object contains a property named "userId". In anothe ...

The image is not displaying on the page

Slider Section (Gray Part) We verified after loading, and the data was spot on. In development mode (F12), we can inspect object information (ImgURL, Text, etc.). However, it is not being displayed. Below is the template code and script code. Thank you. ...

Is there a way to export a modified OBJ geometry from a Three.js scene?

Every time I make changes and export my Three.js scene with a SkinnedMesh model, the original imported model gets saved instead of the updated version. Despite rotating bones and adjusting morph targets, the exported model remains unchanged. Even though t ...

Continuously decrease a sequence of identical numbers in an array through recursion

One of the key challenges was to condense an array of numbers (with consecutive duplicates) by combining neighboring duplicates: const sumClones = (numbers) => { if (Array.isArray(numbers)) { return numbers.reduce((acc, elem, i, arr) => { if ( ...

Display each new array element on a separate line

let team = [['Sara', 'John', 'Kate']] let newTeam = team.map(function(r) { return r; }) outputs [ [ 'Sara', 'John', 'Kate' ] ] Is there a way to modify it so that each value is r ...

Is there a way to link a knockout observable to the jquery barrating plugin?

I have integrated the jquery bar-rating plugin with a knockout viewModel. Currently, all ratings need to be manually selected, but I am looking to convert the variable (let's call it rating) into an observable so that the bar automatically updates whe ...

Updating the route path for version control in Express.js

When working with an ExpressJS application, the following paths should be considered: GET /v1/users/detail GET /v2/users/detail The corresponding routers are as follows: // v1/users.js router.get('/v1/users/detail', (req, res, next) => res. ...

Unable to manipulate JQuery lightSlider slides using element index

I've been working on a new page design at this link: The code is still a work in progress, so bear with me as I test out some functions and scripts. At the end of the first section, there are 4 logos that, when clicked, will trigger a modal to pop u ...

Angular's directives do not trigger the 'viewContentLoaded' event

I recently created a 'light-gallery' directive that relies on the jquery.lightgallery.js plugin to initialize the $.fn.lightGallery() functions. It is crucial for these functions to be executed after the directive template has been compiled and l ...

Strange issue with Firefox when utilizing disabled attribute as "disabled"

I found a curious bug in Firefox: Check out (unfortunately not reproducible in jsfiddle) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> < ...

Display my additional HTML content on the current page

Is it possible for my addon to open a predefined html page in the current window when it is started? And if so, how can this be achieved? Currently, I am able to open my addon page in a new window using the following command: bridge.boot = function() { ...

Tips for testing components with React JS using jest and enzyme

Attempting to perform a unit test on the code snippet below: handleChange = (e) => { let localState = Object.assign({}, this.state) localState[e.target.name] = e.target.value this.setState(localState) this.props.addMetaInformation(localState) } } I&a ...

Is there a sweet TypeScript class constructor that can take in its own instance as an argument?

I have a scenario where I need to read in instances of Todo from a CSV file. The issue is that Papaparse does not handle dynamic conversion on dates, so I'm currently dropping the object into its own constructor to do the conversion: class Todo { ...

Clearing local storage in JavaScript after a certain period of time

On my signup page, I have divided the process into 5 stages and am using the user ID to track which stage they are at by storing it in local storage. However, I would like to automatically remove the ID from local storage if users leave my website without ...