Reformat string containing date with Javascript

前端 未结 3 1164
逝去的感伤
逝去的感伤 2020-11-29 13:44

I have the following string which I ultimately need to have in the format of mm/yy

    var expDate = 2016-03;
    var formatExp = expDate.replace(/-/g , \"/\         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 14:42

    With a RegExp :

    '2016-03'.replace(/^\d{2}(\d{2})-(\d{2})$/, '$1/$2')

提交回复
热议问题