Java time into the string format Date Format

By a new SimpleDateFormat object by object calls the parse method to achieve

Sample code:

String time = "2019-07-23";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
         Date dateTime = null;
         try {
             dateTime = simpleDateFormat.parse(time);
         } catch (ParseException e) {
             e.printStackTrace();
         }

note

  • The string passed to the form and in the form as defined in SimpleDateFormate
  • Write error handling

Guess you like

Origin www.cnblogs.com/youpeng/p/11233707.html