javascript - Which format is better and not time consuming? -
i new web development .. confused time complexity of java script , jquery other programming languages c , c++.
format 1: var cur_month; cur_month = (new date().getmonth()) + 1; // returns 0 11 cur_month = cur_month.tostring().length > 1 ? cur_month : '0' + cur_month; format 2: var cur_month; cur_month = ((new date().getmonth()) + 1).tostring().length > 1) ? ((new date().getmonth()) + 1) : '0' + ((new date().getmonth()) + 1);
in format 2 , accessing month 3 new date objects .. in first format , creating 1 object , accessing .. 1 better format?
format 1 because don't create multiple date object (with different values)
also rewrite last line.
adding string number implicitly casts string.
var cur_month; cur_month = (new date().getmonth()) + 1; cur_month = ( cur_month < 10 ? '0' : '' ) + cur_month;
Comments
Post a Comment