How to replace a string at a particular position

后端 未结 6 1532
深忆病人
深忆病人 2020-12-10 12:30

Is there a way to replace a portion of a String at a given position in java script. For instance I want to replace 00 in the hours column with 12 i

6条回答
  •  [愿得一人]
    2020-12-10 13:04

    The following is one option:

    var myString = "Mar 16, 2010 00:00 AM";
    
    myString = myString.substring(0, 13) + 
               "12" + 
               myString.substring(15, myString.length);
    

    Note that if you are going to use this to manipulate dates, it would be recommended to use some date manipulation methods instead, such as those in DateJS.

提交回复
热议问题