Compare JSONArray and the current server time

0

Cordial greeting,

I have a Mysql database and I pass the value of a column called hour to a JSONArray, my problem is that I do not know how to compare if the time in database is greater than the time in the database server.

JSONArray ja = new JSONArray(result);
ja.getString(3) ---> Este es el arreglo que tiene la hora almacenada en base de datos

And I want to compare it like that, although I know it's not the way:

if (ja.getString(3) >= Time()) { }...
    
asked by user2683734 20.02.2017 в 17:52
source

1 answer

1

I understand that you want to only compare the time, nothing else, which complicates the issue instead of facilitating it :)

Then:

java.util.Date date= new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date); 
// obtienes cada elemento por separado de la fecha y hora actual 
int horas = cal.get(Calendar.HOUR_OF_DAY);
int minutos = cal.get(Calendar.MINUTE);
int segundos = cal.get(Calendar.SECOND);

// Los unes en una cadena
String sActual = horas + "" + minutos + "" + segundos;

//Cadena de tu array, limpiada de los :
String sArray=ja.getString(3).replace(':', '');

//Conviertes a entero los dos valores que quieres comparar
int nActual = Integer.parseInt(sActual);
int nArray = Integer.parseInt(sArray);

// Comparas:

if (nArray >= nActual) { }...
    
answered by 20.02.2017 / 20:14
source