标签:
//今天放假没看东西,贴上以前的基础,没事看着玩
// String->->
var myStr = "My name is LiuYashion";
console.log( myStr.length ); //21
console.log( myStr.charAt(0) ); //M
console.log( myStr.charCodeAt(0) ); //77 (M)
console.log( myStr.indexOf("n") ); //3
console.log( myStr.lastIndexOf("n") ); //20
console.log( String.fromCharCode(77) ); //M
console.log( myStr.replace("My","His") ); //His name is LiuYashion 只能换一次,最前面的一个
console.log( myStr.substring(11,21) ); //LiuYashion,包含11,不包含21
console.log( myStr.toLowerCase() ); //my name is liuyashion
console.log( myStr.toUpperCase() ); //MY NAME IS LIUYASHION
var myStr_1 = " My name is LiuYashion ";
console.log( myStr_1 ); // My name is LiuYashion
console.log( myStr_1.trim() ); //My name is LiuYashion
// Number->->
var myArr = ["M","y"," ","n","a","m","e"," ","i","s"," ","L","i","u","Y","a","s","h","i","o","n"];
console.log( myArr.length ); //21
console.log( myArr.indexOf("n") ); //3
console.log( myArr.lastIndexOf("n") ); //20
// Math->->
console.log( Math.round(3.6) ); //4 四舍五入
console.log( Math.abs(-3.3) ); //3.3 绝对值
console.log( Math.ceil(-3.3) ); //-3 向上取整
console.log( Math.floor(-3.3) ); //-4 向下取整
console.log( Math.pow(2,3) ); //8 2的3次方
console.log( Math.sqrt(9) ); //3 9开方
console.log( Math.max(3.3,15,30) ); //30 最大值
// Date->->
var myDate = new Date(‘2016/3/21 23:11:11‘);
var nowDate = new Date(); //Wed Mar 23 2016 11:02:22 GMT+0800 (中国标准时间)
console.log( nowDate.getFullYear() ); //2016 (number类型)
console.log( nowDate.getMonth() ); //2 月份是0-11
console.log( nowDate.getDate() ); //23 日期是从1开始
console.log( myDate.getDay() ); //1 星期一
console.log( myDate.getHours() ); //23
console.log( myDate.getMinutes() ); //11
console.log( myDate.getSeconds() ); //11
console.log( myDate.setFullYear(2008) ); //1220886671000 距离1970.1.1的毫秒数.
console.log("-------------"+myDate)
console.log( myDate.setMonth(8) ); //1220886671000 距离1970.1.1的毫秒数
console.log( myDate.setDate(8) ); //1220886671000 距离1970.1.1的毫秒数
console.log( myDate ); //Mon Sep 08 2008 23:11:11 GMT+0800 (中国标准时间)
var firstDate = new Date(‘2016/3/24 11:11:11‘);
var secondDate = new Date();
var spare = firstDate - secondDate;
var spare_s = parseInt(spare/1000); // spare_s 总共的秒数
var spare_seconds = spare_s%60; // spare_seconds 余下秒数
var spare_m = parseInt(spare_s/60); // spare_m 总共分钟数
var spare_minutes = spare_m%60; // spare_minutes 余下的分钟
var spare_h = parseInt(spare_m/60); // spare_h 总共小时数
var spare_hours = spare_h%24; // spare_hours 余下小时数
var spare_days = parseInt(spare_h/24); // spare_days 总共的天数
console.log(spare_days+"天"+spare_hours+"小时"+spare_minutes+"分钟"+spare_seconds+"秒");
// 0天21小时18分钟15秒
var date_1 = new Date(‘1970/1/1‘);
console.log( Date.parse(date_1) ); //946656000000,距离1970.1.1的毫秒数
var my_date = new Date();
console.log( my_date.getFullYear()+"/"+ (my_date.getMonth()+1) +"/"+ my_date.getDate() );
//2016/3/23
标签:
原文地址:http://www.cnblogs.com/nemoro1928/p/5397277.html