Android - Get time from EditText inputType=“time”

后端 未结 3 520
广开言路
广开言路 2021-01-23 04:57

I have EditText in my XML file:

   

        
相关标签:
3条回答
  • 2021-01-23 05:35

    this below code will help you

    String string = editText.getText().toString();
    DateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
    Date date = formatter.parse(string);
    
    0 讨论(0)
  • 2021-01-23 05:40

    Try This:

    EditText etExitHouret = (EditText) findViewById(R.id.etExitHour);        
    
    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); // Make sure user insert date into edittext in this format.
    
    Date dateObject;    
    String date;
    String time;
    
    try {
        String dob_var=(etExitHouret.getText().toString());
    
        dateObject = formatter.parse(dob_var);
    
        date = new SimpleDateFormat("dd/MM/yyyy").format(dateObject);
        time = new SimpleDateFormat("h:mmaa").format(dateObject);
        Toast.makeText(getBaseContext(), date + time, Toast.LENGTH_LONG).show();
    } 
    catch (java.text.ParseException e) {
        e.printStackTrace();
    }
    
    0 讨论(0)
  • 2021-01-23 05:41
    String str = editText.getText().toString();
    DateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
    Date date = formatter.parse(str);
    
    0 讨论(0)
提交回复
热议问题