Problem description
Today, the statistics function is added to the website, one of which isWebsite running time:
This function is enabledCurrent TimeAndSite creation timeAfter calculating the difference, the website running time is calculated as N years, N days, n minutes, n seconds. After the code is written, the browser is tested to display the results. It is found that non-IE browser kernels are normally displayed, when the results are displayed in IE browser, they are displayed as follows: undefined: seconds
After troubleshooting, it is found that new date ("15:16:16") in ie11 returns undefined.
Solve the problem
Method 1: Custom Method
Customize a newdate method:
function NewDate(str){ if(!str){ return 0; } arr=str.split(" "); d=arr[0].split("-"); t=arr[1].split(":"); var date = new Date(); date.setUTCFullYear(d[0], d[1] - 1, d[2]); date.setUTCHours(t[0], t[1], t[2], 0); return date; }
Method 2: Use the date. parse () method
'15:16:16 'cannot be used by browsers to correctly generate date objects using new date (STR. The correct usage is '15:16:16 '.
The date string in '/' format is widely supported by various browsers. The date string connected by '-' can only work in chrome.
var timestart = new Date(Date.parse(‘2017-09-01 15:16:16‘.replace(/-/g,"/")))
Reference: 52484806
Internet Explorer new date () return undefined with parameters solution