javascript - how to change the pattern of the datetime-local provided in the html input -


html input of datetime type is

datefield: <input type="datetime-local" data-date="" data-date-format="dd mmmm yyyy, h:mm:ss"> 

script contains below code.

$("input").val(moment().format('yyyy-mm-dd, h:mm:ss'));  $("input").on("change", function() { this.setattribute(     "data-date",     moment(this.value)     .format( this.getattribute("data-date-format") ) ) }).trigger("change") 

i have referred http://jsfiddle.net/g7mvaosl/ wherein date pattern can changed. in similar way, tried use type="datetime-local" doesn't work. how resolve this.

the date picker returns year, month, , day.
console.log(this.value); //returns 2015-08-09

you're asking , additionally hours, minutes, seconds: date picker cannot do.

i'm guessing want use current time h:mm:ss? in code set moment's now.
$("input").val(moment().format('yyyy-mm-dd, h:mm:ss'));

but occurs once, you'd need move line inside on change event.

however, there's no bridge allows add 2 moments together, because won't make sense. adding today + tomorrow double current year, month, etc. instead have use moment.duration(). moment defined single points in time, durations defined length of time. wrote function targeting values need.

function nowasduration(){     return moment.duration({         hours:   moment().hour(),         minutes: moment().minute(),         seconds: moment().second()     }); } 

now can use moment.add().

var = moment(this.value); var b = nowasduration(); var c = a.add(b); 

updated code. http://jsfiddle.net/w7mj7feh/


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -