I am new to Momentjs. I am trying to use it to convert milliseconds to hours and minutes. Below, x is milliseconds
x = 433276000
var y = moment.duration(x, \
You can create a Moment.js date from milliseconds using moment.utc().
var milliseconds = 1000;
moment.utc(milliseconds).format('HH:mm');
In Moment.js duration you can just use Math.trunc for hours if you are expecting it to be over 24hrs. hh:mm:ss format.
var seconds = moment.duration(value).seconds();
var minutes = moment.duration(value).minutes();
var hours = Math.trunc(moment.duration(value).asHours());
see it here: https://codepen.io/brickgale/pen/mWqKJv?editors=1011
moment('2000-01-01 00:00:00').millisecond(XXXXXX).format("HH:mm:ss")
Momentjs itself doesn't support duration, in order to do so, we need a plugin moment-duration-format
To use this plugin follow these steps (for React-js)
import moment from 'moment';
import momentDurationFormatSetup from "moment-duration-format";
var time = moment.duration(value,unit).format('hh:mm:ss',{trim:false})
Note: I have used {trim: false} as extra parameter so that it doesn't trim out extra 0's in the beginning. You can omit it if you want "11:30" instead of "00:11:30".
Try this:
var x = 433276000
var d = moment.duration(x, 'milliseconds');
var hours = Math.floor(d.asHours());
var mins = Math.floor(d.asMinutes()) - hours * 60;
console.log("hours:" + hours + " mins:" + mins);