Get day, month and year separately using SimpleDateFormat

前端 未结 8 874
無奈伤痛
無奈伤痛 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());
        }
    
    0 讨论(0)
  • 2021-02-08 20:23

    Use this to parse "Jan,23,2014"

    SimpleDateFormat fmt = new SimpleDateFormat("MMM','dd','yyyy"); 
    Date dt = fmt.parse("Jan,23,2014");
    

    then you can get whatever part of the date.

    0 讨论(0)
提交回复
热议问题