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
)
);
?>