Connection Database Android Studio passing Date

0

I'm having trouble with the following, I make the connection to the Database all right but in the code I use a Map of parameters because I step userName, password, etc, however I need to pass a variable of type Date tbm. All these variables will be sent to a code in php. How could I 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;
}
    
asked by anonymous 01.05.2017 / 02:37

1 answer

0

Converts the date into milliseconds (long) and saves it to your Map. You can create 2 utility methods to do 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);
}
    
02.05.2017 / 02:13