javascript - jquery convert time from english to french -


i need change time on site english french ie 7:15 pm = 19 h 15. not have access end change time format. using indexof , .replace. works first pm in p how can loop them. here code far.

<script> function myfunction() {   var str = "12:00 test text @ 9:10 pm se second 6:00 pm doe not works.";   var matchs = str.match(/pm/gi); //can used loop amount   var n = str.indexof("pm")-6; //first digit before pm var n2 = str.indexof("pm")-5; //second digit before pm var res = str.charat(n) + str.charat(n2);// add  var myinteger = parseint(res)+12;// make ind , add 12  var str1= str.replace(res ,' '+myinteger).replace('pm','').replace(/pm/g,'').replace(/:/g,' h ').replace(/00/g,' ').replace('am','');// replace   alert(str1);  document.getelementbyid("demo").innerhtml = str1 } 

thanks

maybe this:

var str = $('#time').text();    var t = str.match(/[\d:]+(?= pm)/g);  (var = 0; < t.length; i++) {    var match = t[i].split(':');    var th = +match[0] + 12 + ' h';    var tm = ' ' + match[1];    var ft = th + tm;    var str = str.replace(t[i], ft).replace(/pm/g, '');    $('#time').html(str);    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id = "time">12:00 test text @ 9:10 pm se second 6:00 pm doe not works.</div>

the regex matches numbers (\d) , colon if followed pm (leading space). each match split on : , 12 added first split (to make 24hr clock).


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -