Convert date string to a particular date format “dd-MM-yyyy” in Java

后端 未结 3 1724
一整个雨季
一整个雨季 2020-12-11 09:17

I have multiple contacts with birth dates and all are synced with the mobile device. Now the problem is all contacts have different birthday formats and I want to display al

3条回答
  •  独厮守ぢ
    2020-12-11 09:38

    Simply using SimpleDateFormat class. Something like:

    Date d = Calendar.getInstance().getTime(); // Current time
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); // Set your date format
    String currentData = sdf.format(d); // Get Date String according to date format
    

    Here you can see details and all supported format:

    http://developer.android.com/reference/java/text/SimpleDateFormat.html

提交回复
热议问题