jquery - Need to Get the time in correct format from JavaScript to ISODateString? -
actually trying convert date java script date iso date format time displayed incorrect.in time 14:30 getting 9:30 should 2:30.and need add 30 min time.this function used convert javascript date iso data.
function myfunction1() { var val1="2013-08-08 14:30:59"; var t = val1.split(/[- :]/); alert(t); d = new date(t[0], t[1]-1, t[2], t[3], t[4], t[5]); d = new date(d.gettime() + (30 * 60000)); alert(isodatestring(d)); } function isodatestring(d){ function pad(n){return n<10 ? '0'+n : n} return d.getutcfullyear()+'-' + pad(d.getutcmonth()+1)+'-' + pad(d.getutcdate()) +' ' + pad(d.getutchours())+':' + pad(d.getutcminutes())+':' + pad(d.getutcseconds()) } share me please if know about.i have worked jsfiddle
there no need utc , therefore remove it.
basically you're looking (converting 12 hrs time format)
pad(d.gethours() > 12 ? d.gethours() - 12 : d.gethours()) complete code:
function isodatestring(d) { function pad(n) { return n < 10 ? '0' + n : n } return d.getfullyear() + '-' + pad(d.getmonth() + 1) + '-' + pad(d.getdate()) + ' ' + pad(d.gethours() > 12 ? d.gethours() - 12 : d.gethours()) + ':' + pad(d.getminutes()) + ':' + pad(d.getseconds()) } result:
input: 2013-08-08 14:30:59
output: 2013-08-08 03:00:59 //since increased 30 mins
Comments
Post a Comment