Home > Web Front-end > JS Tutorial > Compatibility issues encountered by Date objects in JavaScript between Safari and IOS

Compatibility issues encountered by Date objects in JavaScript between Safari and IOS

php是最好的语言
Release: 2018-07-28 13:46:19
Original
1827 people have browsed it

Recently, the editor is working on a conference room reservation function. This function is like choosing a seat when buying a movie ticket. You can see which time period the conference room is free, what equipment is available, etc. Since I am making an APP, the APP must be compatible with both Android and IOS. I used Google Chrome for the initial development and debugging. I did not use other browsers for testing. Who knew that there would be a big problem left in the end? hidden dangers. Below is my interface.

Compatibility issues encountered by Date objects in JavaScript between Safari and IOS

Question 1:

This interface uses a lot of date type calculations. When we use JavaScript to instantiate a date object, we can use it like this :

var date =new Date();
Copy after login

The above code is to get the current date. This code can be run in Firefox, Chrome, and Safari browsers. But if I want to get the date based on a string, the problem comes. Look at the code below.

var date =new Date("2016-05-31 08:00");
Copy after login

This code is to get the date specified in the characters. It can be run in Firefox and Chrome, but when placed in Safari, an error will be reported. The error is NaN, which means Not a Number. Because of this error, Apple phones could not run the interface I developed normally. I was almost depressed at the time. I wrote 300 lines of js, almost all of which were related to time, either taking values ​​or assigning values, or calculating. Now IOS not support. . . . . . .

I searched on the Internet and wrote the code like this:

var date =new Date("2016/05/31 08:00");
Copy after login

In this way, Android and IOS can share it. I wrote a function and replaced it!

  1. function GetDateDiff(startDiffTime, endDiffTime) {

  2. /Convert the time format of xxxx-xx-xx to the format of xxxx/xx/xx

  3. startTime = startDiffTime .replace(/\-/g, "/");
  4. endTime = endDiffTime.replace(/\-/g, "/");
  5. };
## Question 2:

New in HTML5 Calendar control, if the control type = "datetime-local", if it is Chrome, the date display format of the control is 2016/05/30 08:00, if it is Safari, the date display format is: 2016-05-31T08 :00, when we use JQuery to obtain and assign values, we must use this method to assign values: If the id of this calendar control is timeDate, the code is as follows:

$("#timeDate').val("2016-05-30T08:30");
Copy after login
Use $("#timeDate') .val("2016/05/30 08:30"); will report an error.

Related articles:

JavaScript's new date and other date functions encountered in Safari Pit

Date object in JavaScript

Related videos:

JS built-in object-Date date object-JavaScript basic video Tutorial

The above is the detailed content of Compatibility issues encountered by Date objects in JavaScript between Safari and IOS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template