JavaScript 常用的技术(陆续更新)
截取字符串(指定长度)
var str = "abc-110001"; //str.substring(起始位置(0开始),截取的长度) str.substring(0,4); //运行结果:abc-
把字符串转换成数字
var str = "0001"; var newValues = parseInt(str);
使用正则表达式判断数字
var gs_reg = /^[0-9]*$/; if(gs_reg.test("as"))
{
alert("I am is numeric!");
}
else
{
alert("Sorry, I am is not numeric!");
}
Javascript IsNaN()函数
isNaN() 函数用于检查其参数是否是非数字值。
检查数字是否非法:
<script> document.write(isNaN(123));
document.write(isNaN(-1.23));
document.write(isNaN(5-2));
document.write(isNaN(0));
document.write(isNaN("Hello"));
document.write(isNaN("2005/12/12")); </script>
输出:
false
false
false
false
true
true 如果返回值是false 说明这个结果是数字来的, 如果是true 那么这个结果不是有效的数字
js 得到当前季度
Date.prototype.getQuarter = function() {
var month = this.getMonth();
if(month < 3) {
return '第一季度';
}else if(month < 6) {
return '第二季度';
}else if(month <9) {
return '第三季度';
}else if(month <12) {
return '第四季度';
}
};
/**
* 获取本周、本季度、本月、上月的开端日期、停止日期
*/
var now = new Date(); //当前日期
var nowDayOfWeek = now.getDay(); //今天本周的第几天
var nowDay = now.getDate(); //当前日
var nowMonth = now.getMonth(); //当前月
var nowYear = now.getYear(); //当前年
nowYear += (nowYear < 2000) ? 1900 : 0; // var lastMonthDate = new Date(); //上月日期
lastMonthDate.setDate(1);
lastMonthDate.setMonth(lastMonthDate.getMonth()-1);
var lastYear = lastMonthDate.getYear();
var lastMonth = lastMonthDate.getMonth(); //格局化日期:yyyy-MM-dd
function formatDate(date) {
var myyear = date.getFullYear();
var mymonth = date.getMonth()+1;
var myweekday = date.getDate(); if(mymonth < 10){
mymonth = "0" + mymonth;
}
if(myweekday < 10){
myweekday = "0" + myweekday;
}
return (myyear+"-"+mymonth + "-" + myweekday);
} //获得某月的天数
function getMonthDays(myMonth){
var monthStartDate = new Date(nowYear, myMonth, 1);
var monthEndDate = new Date(nowYear, myMonth + 1, 1);
var days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
return days;
} //获得本季度的开端月份
function getQuarterStartMonth(){
var quarterStartMonth = 0;
if(nowMonth<3){
quarterStartMonth = 0;
}
if(2<nowMonth && nowMonth<6){
quarterStartMonth = 3;
}
if(5<nowMonth && nowMonth<9){
quarterStartMonth = 6;
}
if(nowMonth>8){
quarterStartMonth = 9;
}
return quarterStartMonth;
} //获得本周的开端日期
function getWeekStartDate() {
var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);
return formatDate(weekStartDate);
} //获得本周的停止日期
function getWeekEndDate() {
var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));
return formatDate(weekEndDate);
} //获得本月的开端日期
function getMonthStartDate(){
var monthStartDate = new Date(nowYear, nowMonth, 1);
return formatDate(monthStartDate);
} //获得本月的停止日期
function getMonthEndDate(){
var monthEndDate = new Date(nowYear, nowMonth, getMonthDays(nowMonth));
return formatDate(monthEndDate);
} //获得上月开端时候
function getLastMonthStartDate(){
var lastMonthStartDate = new Date(nowYear, lastMonth, 1);
return formatDate(lastMonthStartDate);
} //获得上月停止时候
function getLastMonthEndDate(){
var lastMonthEndDate = new Date(nowYear, lastMonth, getMonthDays(lastMonth));
return formatDate(lastMonthEndDate);
} //获得本季度的开端日期
function getQuarterStartDate(){ var quarterStartDate = new Date(nowYear, getQuarterStartMonth(), 1);
return formatDate(quarterStartDate);
} //或的本季度的停止日期
function getQuarterEndDate(){
var quarterEndMonth = getQuarterStartMonth() + 2;
var quarterStartDate = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth));
return formatDate(quarterStartDate);
}
JavaScript 常用的技术(陆续更新)的更多相关文章
- eclipse常用快捷键,这个只要新学会的常用的会陆续更新的。
1.Ctrl+Shift+O 引用包 2.Ctrl+Shift+F 格式化代码 3.Ctrl + / 注释和解除注释代码 4.Ctrl+M 代码最大最小化 5.ctrl+shif ...
- Javascript常用函数收集(不定期更新)
str.replace('/正则表达式/','替换内容'); //正则替换str.match('/正则表达式/','替换内容'); //正则匹配 str.indexOf('查找代码'); //查找是否 ...
- javascript常用代码大全
http://caibaojian.com/288.html 原文链接 jquery选中radio //如果之前有选中的,则把选中radio取消掉 $("#tj_cat .pro_ca ...
- Javascript 常用函数【3】
jquery选中radio //如果之前有选中的,则把选中radio取消掉 $("#tj_cat .pro_category").each(function() { if ($(t ...
- Javascript常用的设计模式详解
Javascript常用的设计模式详解 阅读目录 一:理解工厂模式 二:理解单体模式 三:理解模块模式 四:理解代理模式 五:理解职责链模式 六:命令模式的理解: 七:模板方法模式 八:理解javas ...
- 7 种 Javascript 常用设计模式学习笔记
7 种 Javascript 常用设计模式学习笔记 由于 JS 或者前端的场景限制,并不是 23 种设计模式都常用. 有的是没有使用场景,有的模式使用场景非常少,所以只是列举 7 个常见的模式 本文的 ...
- select元素javascript常用操作 转
/*------------------------------------------------------ *作者:xieyu @ 2007-08-14 *语言:JavaScript *说明:s ...
- 【Android面试】Android面试题集锦 (陆续更新)(最新2012-6-18) eoe上看到的
===============eoeAndroid社区推荐:======================= 1.Android开发新浪面试题[开发者必看哦]下载地址 http://www.eoeand ...
- 【javascript】javascript常用函数大全
javascript函数一共可分为五类: •常规函数 •数组函数 •日期函数 •数学函数 •字符串函数 1.常规函数 javascript常规函数包括以下9个函数: ( ...
随机推荐
- SpringBoot 切换国际化
git:https://github.com/xiaozhuanfeng/demoProj 代码结构: application.properties: spring.messages.basename ...
- spring监听机制——观察者模式的应用
使用方法 spring监听模式需要三个组件: 1. 事件,需要继承ApplicationEvent,即观察者模式中的"主题",可以看做一个普通的bean类,用于保存在事件监听器的业 ...
- ecshop后台增加模块菜单详细教程
我们有时候针对ecshop如此开发,想在后台加一些菜单,最模板以前提供过教程,但是并非很系统,今天最模板抛砖引玉图文教程告诉大家:如何在ecshop后台增加模块菜单! 首先需要修改四个文件:inc_p ...
- 利用Python进行windows系统上的图像识别与点击(Mac OS系统也可以)
系统环境: 1.安装了python 2.安装了pyautogui模块 windows系统:无需安装依赖模块,在cmd中直接输入pip install pyautogui即可完成安装 Mac OS系统: ...
- 001/Go语言构建区块链(mooc)
1.区块链发展与现状 视频地址:https://www.imooc.com/video/17452 注意: 比特币与以太坊最大的区别在于: 以太坊引入了对图灵完美智能合约的支持,人们可以将任何业务逻辑 ...
- JS和C#后台获取网站URL
例:网页URL : http://localhost:8086/index.aspx?topicId=361 1.设置或获取 href 属性中跟在问号后面的部分:window.location.se ...
- Redis数据类型:Hashes、Geo操作指令
Redis数据类型:Hashes.Geo操作指令 Hashes常用操作指令 Redis Hashes是一个键值对的映射表,最对能存储2^32-1(约40亿)个键值对. HSET HGET HSET:将 ...
- (4.23)SQL Server中的加密
转自:https://www.cnblogs.com/CareySon/archive/2012/04/01/SQL-SERVER-Encryption.html 简介 加密是指通过使用密钥或密码对数 ...
- vue自定义组件(通过Vue.use()来使用)即install的使用
在vue项目中,我们可以自定义组件,像element-ui一样使用Vue.use()方法来使用,具体实现方法: 1.首先新建一个loading.vue文件 // Cmponent.vue <te ...
- spring注解之@Scope
转自:https://blog.51cto.com/4247649/2118351 作者:知了123 主要从以下几方面来介绍一下@Scope注解 @Scope注解是什么 @Scope注解怎么使用 @S ...