当前位置:网站首页>new Date converts strings into date formats Compatible with IE, how ie8 converts strings into date formats through new Date, how to replace strings in js, and explain the replace() method in detail
new Date converts strings into date formats Compatible with IE, how ie8 converts strings into date formats through new Date, how to replace strings in js, and explain the replace() method in detail
2022-08-04 03:04:00 【cplvfx】
new Date converts strings into date formats compatible with IE, how ie8 converts strings into date formats through new Date, how to replace strings in js, and the replace() method in detail
//Get the year, month, day, hour, minute and second//Incoming date //Example: 2020-10-27T14:36:23var timeFormatSeconds = function(time, type) {var d = time ? new Date(time) : new Date();if(time){time=time.replace(/-/g,"/"); //For compatibility with IEd = new Date(time);}else{d = new Date();}var year = d.getFullYear();var month = d.getMonth() + 1;var day = d.getDate();var hours = d.getHours();var min = d.getMinutes();var seconds = d.getSeconds();if (month < 10) month = '0' + month;if (day < 10) day = '0' + day;if (hours < 0) hours = '0' + hours;if (min < 10) min = '0' + min;if (seconds < 10) seconds = '0' + seconds;var res = "";switch (type) {case 1:res = (year + '-' + month + '-' + day + ' ' + hours + ':' + min);break;case 2:res = (year + '-' + month + '-' + day);break;default:res = (year + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + seconds);break;}return res;}
The browser will report an error using the replace() method, don't worry, the method execution process is normal
How ie8 converts a string into a date format through new Date
How ie8 converts stringconvert to date format
javaScript ie8 does not support new Date("2017-07-01");
Only supports new Date("2017/07/01")
So in web development, if you need to be compatible with ie, you can use new Date("2017/07/01") to convert the string into time format
Detailed explanation of replace() method
Original
How to replace strings in js-js Tutorial-PHP Chinese Network
Method for string replacement in js:
1. Use regular expressions, the syntax is [str.replace("string to be replaced", "new string")];
2. Use the conventional replacement method, the syntax is [str.replace(/string to be replaced/g, "new string")].
The method of string replacement in js:
Two methods: regular & regular
str.replace("string to be replaced", "new string")
str.replace(/string to be replaced/g, "new string")
For example:
1.
"yyyy-MM-dd-hh-mm-ss".replace("-","/")
The results are as follows:
"yyyy/MM-dd-hh-mm-ss"
2.
"yyyy-MM-dd-hh-mm-ss".replace(/-/g,"/")
The results are as follows:
"yyyy/MM/dd/hh/mm/ss"
In summary:
Regular replacement will only replace the first matching character, regular replacement can replace all
边栏推荐
- Zabbix set up email alert + enterprise WeChat alert
- 移动端响应式适配的方法
- web端动效 lottie-web 使用
- MallBook 助力SKT思珂特教育集团,立足变化,拥抱敏捷交易
- pytorch应用于MNIST手写字体识别
- 一文看懂推荐系统:召回04:离散特征处理,one-hot编码和embedding特征嵌入
- View mysql deadlock syntax
- Zabbix设置邮件告警+企业微信告警
- What is the source of flinkcdc consuming mysql binlog data without sqltype=delete
- [Playwright Test Tutorial] 5 minutes to get started
猜你喜欢
瑞能微计量芯片RN2026的实用程序
sqoop ETL工具
【项目实现】Boost搜索引擎
KingbaseES数据库启动失败,报“内存段超过可用内存”
2022G1工业锅炉司炉考试练习题及模拟考试
sqoop ETL tool
Countdown to 2 days, the "New Infrastructure of Cultural Digital Strategy and Ecological Construction of Cultural Art Chain" will kick off soon
从图文展示到以云为核,第五代验证码独有的策略情报能力
说说数据治理中常见的20个问题
逻辑漏洞----其他类型
随机推荐
Example 041: Methods and variables of a class
多线程间的通信方式你知道几种?
View mysql deadlock syntax
Countdown to 2 days, the "New Infrastructure of Cultural Digital Strategy and Ecological Construction of Cultural Art Chain" will kick off soon
自制蓝牙手机app控制stm8/stm32/C51板载LED
pytorch应用于MNIST手写字体识别
安装postgis时报找不到“POSTGIS_VERSION”这个函数
Good bosses, please ask the flink CDC oracle to Doris, found that the CPU is unusual, a run down
Sfdp 超级表单开发平台 V6.0.5 正式发布
共n级台阶,每次可以上1级或2级台阶,有多少种上法?
Ant - the design of the Select component using a custom icon (suffixIcon attribute) suffixes, click on the custom ICONS have no reaction, will not display the drop-down menu
TOML配置文件格式,YAML最有力的竞争者
全网没有之一的JMeter 接口测试流程详解
Zabbix设置邮件告警+企业微信告警
ingress 待完善
STM8S105k4t6c---------------Light up LED
Big guys, it takes a long time to read mysql3 million single tables, what parameters can be discounted, or is there any way to hurry up
cdh6.x 集成spark-sql
2022年茶艺师(中级)考试试题模拟考试平台操作
tkmapper的crud示例: