-2

I have written code to find out the diff of two Dates. I have successfully done this. but the output has given so long format like that: DIFF-DATE 0.019110277777777778:1.1466166666666666:68.797. But I want to format like that 01:20:59 means HH:mm:ss so, please suggest somethings

Here's my Code:

/*---StrtDate---*/

   componentDidMount(){
        let{StrtDate}=this.state

        this.setState({ StrtDate: moment(new Date()) })
    }

/*---EndDate--*/

  bookingEndTime(){
        let { StrtDate, EndDate}=this.state;
        var end = moment(new Date());
        this.setState({ EndDate: end}, ()=> {
        var duration = moment.duration(end.diff(StrtDate));
        var Hours = duration.asHours();
        var Minutes = duration.asMinutes();
        var Seconds = duration.asSeconds();
        console.log('DIFF-DATE', (Hours +":" + Minutes+ ":" + Seconds))
        })


    }

Vijay Gehlot
  • 80
  • 1
  • 10

1 Answers1

0

Visit momentjs formatting: https://momentjs.com/docs/#/displaying/

Below is a sample


var moment = require("moment"); 
var input = "2020-02-27T01:23:44-05:30";
var converted = moment(input).format("HH:mm:ss"); 
console.log(converted);
joy08
  • 9,004
  • 8
  • 38
  • 73