How to convert hours and minutes to minutes with moment.js?

前端 未结 5 666
时光说笑
时光说笑 2021-01-01 17:19

I need to convert hours and minutes in minutes values. With pure JavaScript Date object I do the following:

var d = new Date();
var minutes = d.getHours() *          


        
5条回答
  •  生来不讨喜
    2021-01-01 17:42

    const moment = require('moment')
    var date = new Date()
    console.log(date) // 2018-11-09T10:01:33.131Z
    
    // 1.
    console.log( 'object', moment(new Date()).toObject() )
    // { years: 2018,
    // months: 10,
    // date: 9,
    // hours: 13,
    // minutes: 1,
    // seconds: 33,
    // milliseconds: 135 }
    
    // 2.
    console.log( 'array', moment(new Date()).toArray() ) // array [ 2018, 10, 9, 13, 1, 33, 141 ]
    
    // 3.
    console.log( 'year', moment(new Date()).toObject().years ) // year 2018
    console.log( 'day of month', moment(new Date()).toObject().date ) // day of month 9
    console.log( 'hours', moment(new Date()).toObject().hours ) // hours 13
    console.log( 'minutes', moment(new Date()).toObject().minutes ) // minutes 1
    console.log( 'seconds', moment(new Date()).toObject().seconds ) // seconds 33
    console.log( 'milliseconds', moment(new Date()).toObject().milliseconds ) // milliseconds 139
    
    // 4.
    console.log( 'weeks', moment(new Date()).weeks() ) // weeks 45
    console.log( 'day of week', moment(new Date()).days() ) // day of week 5
    console.log( 'day of month', moment(new Date()).date() ) // day of month 9
    console.log( 'hours', moment(new Date()).hours() ) // hours 13
    console.log( 'minutes', moment(new Date()).minutes() ) // minutes 1
    console.log( 'seconds', moment(new Date()).seconds() ) // seconds 33
    console.log( 'milliseconds', moment(new Date()).milliseconds() ) // milliseconds 141
    

提交回复
热议问题