js Math Date 字符串操作
2021-03-27 19:24
标签:get 最大 str date() span 绝对值 tle div 最小 js Math Date 字符串操作 标签:get 最大 str date() span 绝对值 tle div 最小 原文地址:https://www.cnblogs.com/qilin20/p/12618951.htmlDOCTYPE html>
html>
head>
meta charset="utf-8">
title>title>
script type="text/javascript">
var s = "skckcdjdksla145c45s.cs12s";
document.write("s:"+s+"
");
document.write("s.length:"+s.length+"
");
document.write("s.charAt():"+s.charAt(5)+"
");//下标从0开始,d
document.write("s.indexOf():"+s.indexOf(‘c‘)+"
");//下标从0开始,2
document.write("s.lastIndexOf():"+s.lastIndexOf(‘c‘)+"
");//下标从0开始,20
document.write("s.substring(1,3):"+s.substring(1,3)+"
");//kc
document.write("s.substr(1,3):"+s.substr(1,3)+"
");//kvk
document.write("s.toUpperCase():"+s.toUpperCase()+"
");//SKCKCDJDKSLA145C45S.CS12S
document.write("s.split():"+s.split(‘k‘)+"
");//s,c,cdjd,sla145c45s.cs12s
document.write("s.replace():"+s.replace("\\d","-")+"
");
document.write("s.match():"+s.match("\\d")+"
");
document.write("s.search():"+s.search("\\d")+"
");//12
document.write("--------------Date--------------------
")
var date = new Date();
document.write("当前时间为:"+date+"
")
document.write("当前时间距1970.01.01.00:00:00的毫秒值 :"+date.getTime()+"
");//距1970.01.01.00:00:00的毫秒值
document.write("当前年为:"+date.getFullYear()+"
")//年
document.write("当前月为:"+date.getMonth()+1+"
")//月
document.write("当前日为:"+date.getDay()+"
")//日
document.write("当前该月的第几天:"+date.getDate()+"
")//该月中某天
document.write("小时为:"+date.getHours()+"
")//小时数
document.write("分钟为:"+date.getMinutes()+"
")//分钟
document.write("毫秒为:"+date.getMilliseconds()+"
")//毫秒
document.write("当前日期为:"+date.toLocaleString()+"
")//以本地环境显示Date的日期和时间
document.write("--------------Math--------------------
")
document.write("最大值为:"+Math.max(5,50,2.5,100.2)+"
")//最大值
document.write("最小值为:"+Math.min(5,50,2.5,100.2)+"
")//最小值
document.write("绝对值为:"+Math.abs(-100)+"
")//绝对值
document.write("四舍五入为:"+Math.round(2.6)+"
")//四舍五入
document.write("随机数为:"+Math.random()+"
")//随机数
document.write("小于指定值的最大整数为:"+Math.floor(2.5)+"
")//小于指定值的最大整数
document.write("大于指定值的最小整数为:"+Math.ceil(2.5)+"
")//大于指定值的最小整数
script>
head>
body>
body>
html>
文章标题:js Math Date 字符串操作
文章链接:http://soscw.com/index.php/essay/68700.html