Help with the time I can not show am or pm in my database

-2

I have this code in android studio to show the time in an EdiText.

//MOSTRAMOS HORA
   Thread t = new Thread()
   {
       @Override
       public  void run()
       {
           try{
               while(!isRestricted()){
                   Thread.sleep(1000);
                   runOnUiThread(new Runnable() {
                       @Override
                       public void run() {
                           hora=(EditText)findViewById(R.id.ethora);
                           long date=System.currentTimeMillis();
                           java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("hh:mm:ss a");
                           String dateString=sdf.format(date);
                           hora.setText(dateString);
                       }
                   });
               }
           }catch (InterruptedException e)
           {}
       }
   };
   t.start();

So far so good, it shows me the time in the EditText putting me am or pm

Now I try to save the time in my database in this way.

    hora.getText().toString()

if you save it but it does not show me in my database if it's am or pm.

This is the structure of my database.

  CREATE TABLE Tiempo (

  'Fecha' date DEFAULT NULL,
  'hora' time DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

I add my PHP code

<?php  

       require('conexion.php');

        $Fecha=$_POST['Fecha'];
        $hora=$_POST['hora'];

        // Sentencia 
        $comando = "INSERT INTO Tiempo ( ".
            " Fecha," .
            " hora)" .
            " VALUES( ?,?)";

        // Preparar la sentencia
        $sentencia =$conn->prepare($comando);

         $sentencia->execute(
            Array{
                $Fecha,
                $hora
            )
        );

?>
    
asked by Sofia 15.06.2017 в 19:25
source

1 answer

0

you can save the time in the database like this:

hora.getText().toString("hh:mm:ss a");

Or you can use the 24 hour format to save it and convert it when you get it without problems:

hora.getText().toString("HH:mm:ss");
    
answered by 16.06.2017 в 00:07