zoukankan      html  css  js  c++  java
  • javaScript(Date与Math的API)

    Math

    Math的两个属性值

    E

    E为一个常量,其值为2.7182818

    PI

    PI为圆周率, 值为3.1415926

    abs();

    绝对值

    var a = - 29.3;
    var info = Math.abs(a);
    console.log(info);//29.3
    

    ceil();

    向上取整

    var a = -35.23;
    var info1 = Math.ceil(a);//-35
    
    var b = 35.23;
    var info2 = Math.ceil(b);//36
    

    floor();

    向下取整

    var a = -25.23;
    var info1 = Math.floor(a);//-26
    
    var b = 25.23;
    var info2 = Math.floor(b);//25
    

    round();

    四舍五入取整

    var a = 25.56;
    var info1 = Math.round(a);//26
    
    var b = 12.12;
    var info2 = Math.round(b);//12
    

    max();

    取最大值

    var a = 10;
    var b = 20;
    
    var info = Math.max(a,b);//20
    

    min ();

    取最小值

    var a = 10;
    var b = 20;
    
    var info = Math.min(a,b);//10
    

    pow();

    求幂

    var x = 2;
    var y = 3;
    
    var info = Math.pow(x,y);//x**y 8
    

    random

    0到1的随机数

    var a = Math.floor(Math.random() * 3);//取值为0,1,2三个间随机一个
    

    sin();

    正弦,以弧度表示角 返回值在-1到1之间

    var a = Math.PI;
    var info = sin(a/2);//1
    

    cos();

    余弦 返回值在-1到1之间

    var info = Math.cos(0);//1
    

    tan();

    正切

    sqrt();

    开方

    var info = Math.sqrt(Math.pow(3,2) + Math.pow(4,2));//勾三股四弦五
    

    Date 日期

    new Date();

    通过构造函数来创建一个日期

    var oDate = new Date();
    console.log(oDate);//现在的时间
    

    getFullYear();

    获取年份

    var oDate = new Date();
    var info = oDate.getFullYear();
    

    getMonth();

    获取月份(0-11)

    var oDate = new Date();
    var info = oDate.getMonth();
    

    getDate();

    获取一个月中的某一天(1-31)

    var oDate = new Date();
    var info = oDate.getDate();
    

    getHours();

    获取小时

    var oDate = new Date();
    var info = oDate.getHours();
    

    getMinutes

    获取分钟

    var oDate = new Date();
    var info = oDate.getMinutes();
    

    getSeconds();

    获取秒

    var oDate = new Date();
    var info = oDate.getSeconds();
    

    getMillisconds();

    获取毫秒

    var oDate = new Date();
    var info = oDate.getMilliscond();
    

    getTime();

    返回一个数值,从1970年1月1日0时0分0秒距离该日期对象所代表时间的毫秒数。

    var oDate = new Date();
    var info = oDate.getTime();
    

    toLocaleString();

    把时间对象变成一个字符串

    var oDate = new Date();
    var info = oDate.toLocaleString();
    

    parse();

    将日期转化为毫秒值

    var a = '1980-8-5 11:20:30';
    var info = Date.parse(a);
    
  • 相关阅读:
    252个基本词根详解
    记忆宫殿|一个故事轻松记忆常见252个英语字根(190~252)
    海外旅游最常用的100句英语口语
    与老外见面的10大经典句
    ReportManager
    ContextLoader
    Workflow License invalid!!
    JD-GUI
    DJ Java Decompiler
    AndroChef Java Decompile
  • 原文地址:https://www.cnblogs.com/strongtyf/p/11844429.html
Copyright © 2011-2022 走看看