java string date conversion

后端 未结 2 546
闹比i
闹比i 2021-01-27 10:40

I want to convert a string to date before storing it and I used

SimpleDateFormat format = new SimpleDateFormat(\"yyyy-mm-dd\");
Date returnDate = format.parse(d         


        
相关标签:
2条回答
  • 2021-01-27 11:13

    In your DateFormat use MM for month instead of mm, that is for minutes

    Reference: http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

    0 讨论(0)
  • 2021-01-27 11:22

    You can use like this :

    Date mDate= new Date(System.currentTimeMillis());
            SimpleDateFormat mDateFormat= new SimpleDateFormat("dd MMM yyyy HH:mm a");
            String dateformat=mDateFormat.format(mDate);
    
    
    the string ["dd MMM yyyy HH:mm a"]  can be changed according to need of formate.
    
    Like in your case : "yyyy-mm-dd
    
    0 讨论(0)
提交回复
热议问题