How to get current date with the time in js?

3

How to get current date with the time in js?

I need to know how many days ran after a certain date. I'm using the momentjs

var start = moment( "2016/06/17" );
var end = moment( new Date() );
var time = date_start.to(date_end);
console.log( moment.duration(time, 'days').humanize());

My problem, is that for the same day, I need the time difference of the date. Only the schedules are zeroed, so the difference is zero.

    
asked by anonymous 17.06.2016 / 22:45

1 answer

3

You can use the diff function of momentjs.E when creating a new moment () you are already creating it with the current date.

[EDITED]

If you want the text to appear in Portuguese simply add the pt-br.js library and put it as the first command of js moment.locale ('pt-BR');

moment.locale("pt-BR");
var start = moment("2016-06-17T09:00:00");
var end = moment();

console.log(start);
console.log(end);
console.log(moment.duration(end.diff(start,true)).humanize());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/locale/pt-br.js"></script>
    
17.06.2016 / 23:18