常用工具函数
来源:互联网 发布:node v0.12.4 x64.msi 编辑:程序博客网 时间:2024/05/21 11:09
1、日期格式化
dateFormat = function(date, formatStr){ var str = formatStr; var Week = ['日','一','二','三','四','五','六']; str=str.replace(/yyyy|YYYY/,date.getFullYear()); str=str.replace(/yy|YY/,(date.getYear() % 100)>9?(date.getYear() % 100).toString():'0' + (date.getYear() % 100)); str=str.replace(/MM/,date.getMonth()>9?date.getMonth().toString():'0' + date.getMonth()); str=str.replace(/M/g,date.getMonth()); str=str.replace(/w|W/g,Week[date.getDay()]); str=str.replace(/dd|DD/,date.getDate()>9?date.getDate().toString():'0' + date.getDate()); str=str.replace(/d|D/g,date.getDate()); str=str.replace(/hh|HH/,date.getHours()>9?date.getHours().toString():'0' + date.getHours()); str=str.replace(/h|H/g,date.getHours()); str=str.replace(/mm/,date.getMinutes()>9?date.getMinutes().toString():'0' + date.getMinutes()); str=str.replace(/m/g,date.getMinutes()); str=str.replace(/ss|SS/,date.getSeconds()>9?date.getSeconds().toString():'0' + date.getSeconds()); str=str.replace(/s|S/g,date.getSeconds()); return str;}
调用:
dateFormat(new Date(), 'MM-dd hh:mm');
2、获取URL中参数值
用正则表达式:
function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return decode(r[2]); return null; }
不用正则表达式:
function getQueryString (str,name) { var string = window.location.search.substr(1) || str.substr(1); if( !string ) return; var arr = string.split('&'); for (var i = 0; i < arr.length; i++) { var item = arr[i].split('='); if(item.length < 2) continue; if(item[0] === name) return decodeURI(item[1]); };}
阅读全文
0 0
- 常用工具函数
- JavaScript常用工具和函数
- C/C++常用工具函数
- Extjs常用工具函数详解
- 【python】几个常用工具函数
- JS常用工具函数整理
- ExtJS 常用工具函数
- php常用工具函数
- [ACM]常用工具函数整理
- Jquery常用工具函数总结
- iOS 常用工具函数
- Android 常用工具函数
- Jni 常用工具函数
- jQuery 常用工具函数
- jQuery-常用工具函数
- Python 常用工具函数
- JavaScript常用工具函数
- Prototype 1.6 边学边译 -- 常用工具函数
- 在查询语句中使用 NOLOCK 和 READPAST
- MySQL理解索引、添加索引的原则
- android-应用签名
- 检查更新
- caffe->tensorflow模型出错:TypeError: Descriptors should not be created directly
- 常用工具函数
- Python3模块详解--老司机工具urllib模块详解之urllib.request子模块
- JAVA IO(BIA)总结
- oracle中的over(partition by )的用法总结
- Java实现远程桌面连接
- Elasticsearch Centos7 安装
- 【android学习】四大组件-Content Provider(内容提供者)
- 对接支付宝接口时,不使用SDK,调用成功但是返回的数据一直验签失败问题解决方案
- multisim仿真时为什么改一个vcc值,却全部变了