Connection Android Studio Database Passing Date

Asked

Viewed 127 times

0

I’m having trouble with the following, I make the connection with the database everything right but in the code I use a parameter Map because I pass username, password, etc., but I need to pass a variable of type Date tbm. All these variables will be sent to a php code. How Could You Solve This??

Follow the code below:

private Map<String, String> params;

public RegisterRequest(String name, String username, String birthDate, String password, Response.Listener<String> listener, String email, int gender)
{
    super(Method.POST, REGISTER_REQUEST_URL, listener, null);
    params = new HashMap<>();
    params.put("userName", name);
    params.put("userNick", username);
    params.put("userPassword", password);
    params.put("userBirthDate", birthDate);
    params.put("userEmail", email);
    params.put("userGender", gender + "");
}



@Override
public Map<String, String> getParams() {
    return params;
}

1 answer

0

Convert the date to milliseconds (long) and store it in your Map. You can create 2 utility methods to make this conversion. For example:

public long DateInMillis(int year, int month, int day, int hours, int minutes, int seconds) {
    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, year);
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DAY_OF_MONTH, day);
    c.set(Calendar.HOUR_OF_DAY, hours);
    c.set(Calendar.MINUTE, minutes);
    c.set(Calendar.SECOND, seconds);

    return c.getTimeInMillis();
}

public CharSequence FormattedDateFromMillis(Context context, long dateInMillis){
    return DateUtils.getRelativeTimeSpanString(context, dateInMillis);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.