Parse string with integer value to date

前端 未结 4 1182
梦毁少年i
梦毁少年i 2021-01-15 21:37

I have a string with this value, for example: \"20130211154717\" I want it to be like \"2013-02-11 15:47:17\". How can I do that?

4条回答
  •  长发绾君心
    2021-01-15 22:26

    You can use regular expressions for that:

    String formattedDate = plainDate.replaceFirst(
            "(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})",
            "$1-$2-$3 $4:$5:$6");
    

    Though, I like assylias's SimpleDateFormat answer better. :-)

提交回复
热议问题