zoukankan      html  css  js  c++  java
  • js Math Date 字符串操作

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title></title>
            <script type="text/javascript">
                var s = "skckcdjdksla145c45s.cs12s";
                document.write("s:"+s+"<br>");
                document.write("s.length:"+s.length+"<br>");
                document.write("s.charAt():"+s.charAt(5)+"<br>");//下标从0开始,d
                document.write("s.indexOf():"+s.indexOf('c')+"<br>");//下标从0开始,2
                document.write("s.lastIndexOf():"+s.lastIndexOf('c')+"<br>");//下标从0开始,20
                document.write("s.substring(1,3):"+s.substring(1,3)+"<br>");//kc
                document.write("s.substr(1,3):"+s.substr(1,3)+"<br>");//kvk
                document.write("s.toUpperCase():"+s.toUpperCase()+"<br>");//SKCKCDJDKSLA145C45S.CS12S
                document.write("s.split():"+s.split('k')+"<br>");//s,c,cdjd,sla145c45s.cs12s
                document.write("s.replace():"+s.replace("\d","-")+"<br>");
                document.write("s.match():"+s.match("\d")+"<br>");
                document.write("s.search():"+s.search("\d")+"<br>");//12
                document.write("--------------Date--------------------<br>")
                var date = new Date();
                document.write("当前时间为:"+date+"<br>")
                document.write("当前时间距1970.01.01.00:00:00的毫秒值 :"+date.getTime()+"<br>");//距1970.01.01.00:00:00的毫秒值 
                document.write("当前年为:"+date.getFullYear()+"<br>")//
                document.write("当前月为:"+date.getMonth()+1+"<br>")//
                document.write("当前日为:"+date.getDay()+"<br>")//
                document.write("当前该月的第几天:"+date.getDate()+"<br>")//该月中某天 
                document.write("小时为:"+date.getHours()+"<br>")//小时数
                document.write("分钟为:"+date.getMinutes()+"<br>")//分钟
                document.write("毫秒为:"+date.getMilliseconds()+"<br>")//毫秒
                document.write("当前日期为:"+date.toLocaleString()+"<br>")//以本地环境显示Date的日期和时间
                document.write("--------------Math--------------------<br>")
                document.write("最大值为:"+Math.max(5,50,2.5,100.2)+"<br>")//最大值
                document.write("最小值为:"+Math.min(5,50,2.5,100.2)+"<br>")//最小值
                document.write("绝对值为:"+Math.abs(-100)+"<br>")//绝对值
                document.write("四舍五入为:"+Math.round(2.6)+"<br>")//四舍五入
                document.write("随机数为:"+Math.random()+"<br>")//随机数
                document.write("小于指定值的最大整数为:"+Math.floor(2.5)+"<br>")//小于指定值的最大整数
                document.write("大于指定值的最小整数为:"+Math.ceil(2.5)+"<br>")//大于指定值的最小整数
            </script>
        </head>
        <body>
            
        </body>
    </html>
  • 相关阅读:
    Linux基础命令grep(如何过滤字符串)
    Linux基础命令wc(如何统计文件的行数?如何统计文件的字节数?)
    Linux基础命令tr(如何替换字符)
    django4
    django3
    django2
    django1
    jQuery2
    jQuery1
    事件
  • 原文地址:https://www.cnblogs.com/qilin20/p/12618951.html
Copyright © 2011-2022 走看看