Parse string with integer value to date

前端 未结 4 1156
梦毁少年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:18

    You can use the substring() method to get what you want:

    String data = "20130211154717";
    String year = data.substring(0, 4);
    String month = data.substring(4, 2);
    // etc.
    

    and then string them together:

    String formatted = year + "-" + month + "-" + . . .
    

提交回复
热议问题