Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of Date of Safari browser in JS

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you what is the use of the Date of the Safari browser in JS, I believe most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

When dealing with Date in js, it is found that Safari and other browsers do not support the same way.

1. For example: 2017-01-01 12:00:00

In other browsers, there is no problem with using strings in this format for new Date operations, but Invalid Date is prompted in Safari

Date string in'- 'format is not supported in Safari. Replace it with' / 'and change it to 12:00:00 on 2017-01-01. It can be used normally.

two。 For example: 2017/01/01T11:00:00

The date string in this format is also not supported in Safari. You need to replace the'T'in the string with a space.

Into 11:00:00 format on 2017-01-01

The following is the function I wrote to format the date string. Although it is not perfect, I haven't found any problems yet.

/ * formatted time string * / * datetimeString: a time string that conforms to the time format * / / * returns the formatted time string: YYYY-MM-DD hh:mm:ss*/formatDatetime = function (datetimeString) {var datetime; if (isNaN (Date.parse (datetimeString) datetime = new Date (Date.parse (datetimeString.replace (/-/ g,'/'). Replace (/ Tamp g,'')) Else datetime = new Date (Date.parse (datetimeString)); var year = datetime.getFullYear (); / * year * / var month = datetime.getMonth () + 1 beat * month * / var date = datetime.getDate (); / * Day * / var hour = datetime.getHours (); / * hour * / var minute = datetime.getMinutes (); / * minutes * / var second = datetime.getSeconds () / * the format of January, day, hour, minute and second * / month = month < 10?'0' + month: month; date = date < 10?'0' + date: date; hour = hour < 10?'0' + hour: hour; minute = minute < 10?'0' + minute: minute; second = second < 10?'0' + second: second Return year +'-'+ month +'-'+ date +'+ hour +':'+ minute +':'+ second;}; these are all the contents of the article "what is the use of Date in Safari browsers in JS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report