date - Splitting string which includes( / and : ) into an array in Javascript -


i have string includes date , time together. need of them seperated in cases. string : 28/08/2015 11:37:47

there solutions in there not fix problem

var date = "12/15/2009"; var parts = date.split("/"); alert(parts[0]); // 12 alert(parts[1]); // 15 alert(parts[2]); // 2009 

this similar thing said above, need split of them.

thank help

if have datetime format i'd suggest simple regex

"28/08/2015 11:37:47".split(/\/|\s|:/) 

this splits on / space , colon

and return

 ["28", "08", "2015", "11", "37", "47"] 

edit per question asked in comment

function parse() {    /** input format needs day/month/year in numbers work **/    var datetime= document.getelementbyid("datetime").value;    var time = document.getelementbyid("time").value;    var output = document.getelementbyid("output")    var datetimearr = datetime.split(/\/|\s|:/);    var timearr = time.split(/:/);    var date = new date(datetimearr[2],datetimearr[1]-1,datetimearr[0],datetimearr[3],datetimearr[4],datetimearr[5]);    date.sethours(date.gethours()+(parseint(timearr[0])));//parseint needed otherwise default string concatenation    date.setminutes(date.getminutes()+(parseint(timearr[1])));    date.setseconds(date.getseconds()+(parseint(timearr[2])));    output.value = date.tostring();  }
date time: <input type="text" value="28/08/2015 11:37:47" id="datetime"><br/>  time add: <input type="text" value="11:37:47" id="time"><input type="button" value="calculate!" onclick="parse()"><br/>  <textarea  id="output" placeholder="output comes here" style="width:400px;height:100px;"></textarea>


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -