javascript - Is there any way of making this function more efficient in a standard browser? -


while profiling web app in chrome found following function function taking large percentage of total runtime app (which reasonable considering how used - maybe 1000 times each page load). therefore wonder if has suggestions of how improved increase performance?

function getdate(datestring) {     re = datestring.split(/\-|\s/);     return new date(re.slice(0, 3).join('/') + ' ' + re[3]); } 

this function given string in form: "yyyy-mm-dd hh:mm:ss", example: "2014-06-06 23:45:00", , returns javascript date.

i using jquery option.

not using many array operations, , not using global re variable, should help:

function getdate(datestring) {     return new date(datestring.replace(/-/g, "/")); } 

however, notice yyyy-mm-dd hh:mm:ss valid date format parsed date constructor directly (ok, maybe not in older ies), in standard browser work well:

function getdate(datestring) {     return new date(datestring); } 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -