0

I need to format time, for example I have a value 01:05 I need to add am or pm to time.

$('.clockpicker').clockpicker({
    afterDone: function() {            
       var time = $('#time').val();            
       console.log(moment(time ).format('h:mm a'));      
    }
});
Meer
  • 2,765
  • 2
  • 19
  • 28
user3351236
  • 2,488
  • 10
  • 29
  • 52

2 Answers2

0

You should on the twelve hour format, bydeafult it is false, use like this

$('.clockpicker').clockpicker({
    twelvehour: 'true',
    afterDone: function() {            
        var time = $('#time').val();            
        console.log(moment(time ).format('h:mm a'));      
    }
});
RAUSHAN KUMAR
  • 5,846
  • 4
  • 34
  • 70
  • I got error Deprecation warning: value provided is not in a recognized ISO format. Also I just need to add am or pm to date. – user3351236 Feb 20 '17 at 08:03
  • I do not need to add twelvehour mode. I need to get the #time value (01:05) in a variable and format it adding "01:05 am". – user3351236 Feb 20 '17 at 08:09
0

Just use moment parsing with format, see moment(String, String);, in your case use moment(time, 'hh:mm') instead of moment(time)

$('.clockpicker').clockpicker({
    afterDone: function() {            
        var time = $('#time').val();            
        console.log(moment(time, 'hh:mm').format('hh:mm a'));      
    }
});
VincenzoC
  • 30,117
  • 12
  • 90
  • 112