Get day, month and year separately using SimpleDateFormat

前端 未结 8 872
無奈伤痛
無奈伤痛 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:19

    public static String getDate(long milliSeconds, String dateFormat) {
            // Create a DateFormatter object for displaying date in specified
            // format.
            SimpleDateFormat formatter = new SimpleDateFormat(dateFormat,
                    Locale.getDefault());
    
            // Create a calendar object that will convert the date and time value in
            // milliseconds to date.
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(milliSeconds);
            return formatter.format(calendar.getTime());
        }
    

提交回复
热议问题