Get day, month and year separately using SimpleDateFormat

前端 未结 8 891
無奈伤痛
無奈伤痛 2021-02-08 19:45

I have a SimleDateFormat like this

SimpleDateFormat format = new SimpleDateFormat(\"MMM dd,yyyy  hh:mm\");
String date = format.format(Date.parse(p         


        
8条回答
  •  滥情空心
    2021-02-08 20:02

    If you need to get the values separately, then use more than one SimpleDateFormat.

    SimpleDateFormat dayFormat = new SimpleDateFormat("dd");
    String day = dayFormat.format(Date.parse(payback.creationDate.date));
    
    SimpleDateFormat monthFormat = new SimpleDateFormat("MM");
    String month = monthFormat .format(Date.parse(payback.creationDate.date));
    

    etc.

提交回复
热议问题