Converting date-string to a different format

后端 未结 5 1170
再見小時候
再見小時候 2020-11-28 11:29

I have a string containing a date in the format YYYY-MM-DD.

How would you suggest I go about converting it to the format DD-MM-YYYY in the

5条回答
  •  眼角桃花
    2020-11-28 12:00

    If you're not looking for String to Date conversion and vice-versa, and thus don't need to handle invalid dates or anything, String manipulation is the easiest and most efficient way. But i's much less readable and maintainable than using DateFormat.

    String dateInNewFormat = dateInOldFormat.substring(8) 
                             + dateInOldFormat.substring(4, 8) 
                             + dateInOldFormat.substring(0, 4)
    

提交回复
热议问题