美文网首页
Date 和 math函数

Date 和 math函数

作者: 缘之空_bb11 | 来源:发表于2024-06-04 17:04 被阅读0次

Date 日期

JavaScript Date(日期)对象

方法 描述
getDate() 以数值返回天(1-31)
getDay() 以数值获取周名(0-6)
getFullYear() 获取四位的年(yyyy)
getHours() 获取小时(0-23)
getMilliseconds() 获取毫秒(0-999)
getMinutes() 获取分(0-59)
getMonth() 获取月(0-11)
getSeconds() 获取秒(0-59)
getTime() 获取时间(从 1970 年 1 月 1 日至今毫秒数)

    // 时间处理: 付款截止时间 - 现在时间 = 转换成时分秒
    dealDateToTime(payLastDate, date = new Date()) {
         let lastDateTime = new Date(payLastDate)               
         let diff = lastDateTime.getTime() - date.getTime()
         // 小时
         let hours = Math.floor(diff / (3600 * 1000)) // 计算出小时数
         let lessHours = Math.floor(diff % (3600 * 1000)) // 计算小时数后剩余的毫秒数
         // 分钟
         let minutes = Math.floor(lessHours / (60 * 1000)) // 计算相差分钟数
         let lessMinutes = Math.floor(lessHours % (60 * 1000)) // 计算小时数后剩余的毫秒数
         // 秒
         let second = Math.floor(lessMinutes / 1000) // 计算分钟数后剩余的毫秒数
    
         return hours.toString().padStart(2,0) + '时' +  minutes.toString().padStart(2,0) + '分' +  second.toString().padStart(2,0) + '秒'
        }

      //  打印:   01 时 25 分08 分


Math() 函数

Javascript Math常用函数

相关文章

  • Javascript的Math对象

    注释:Math对象并不像Date和String那样是对象的类。因此没有构造函数Math()。可以直接通过Math作...

  • JS基础-Math内置对象

    Math 对象并不像 Date 和 String 那样是对象的类,因此没有构造函数 Math()。 语法: Mat...

  • Date Math

    6.5 date math对象的学习 Math对象 Math对象:仅专门提供数学计算的方法Math对象没有构造函数...

  • JS Math对象

    Math 对象用于执行数学任务。Math 对象并不像 Date 和 String 那样是对象的类,因此没有构造函数...

  • JavaScript第二天

    定义函数 1、date()对象 1.1、date对象用于处理时间和日期 /1.2、Math对象 如果是整数,取整之...

  • 【JavaScript的Math函数和常量】

    概要: Math是一个对象,其属性为若干有用的函数和常量。他和Date、String不同,Math不是对象的类。没...

  • Math和Date

    Date Date.now()now方法返回当前距离1970年1月1日00:00:00的毫秒数Date.now()...

  • Math和Date

    Math对象 Math常用API 生成随机数 四舍五入 最大值 最小值 绝对值 向上取整 向下取证 π 各进制间数...

  • Math和Date

    Math对象 Math对象 里面提供的方法,可以帮助我们解决算术问题 提供的方法: Math.random() 返...

  • JavaScript之内置函数 Date和Math

    日期函数Date() 声明日期函数 Date还可以当作构造函数使用。对它使用new命令,会返回一个Date对象的实...

网友评论

      本文标题:Date 和 math函数

      本文链接:https://www.haomeiwen.com/subject/dyytqjtx.html