React-native-modal-datetime-picker: Add a point (.) to AM and PM and library translation

Created on 14 Aug 2019  路  4Comments  路  Source: mmazzarolo/react-native-modal-datetime-picker

Hi, I am using this package and it works fine for me, attached captures:

Captura de Pantalla 2019-08-13 a la(s) 4 32 24 p  m
Captura de Pantalla 2019-08-13 a la(s) 4 33 03 p  m

But I need 2 things:

  1. How do I add a point (.) to AM and PM format? I need to display A.M and P.M because the api that I am using in this project is like this and does not accept it without a point.

  2. How to translate the library into Spanish? to display date in spanish

Thanks in advance
regards

question

Most helpful comment

@pixsolution the locale prop is used to render the date/time based on regions, basically it will translate it to Spanish: Monday -> Lunes

The idea is that the DateTimePicker will give you a value and you can format that value based on your needs.

Formatting is done using libraries like this:

All 4 comments

@pixsolution

  1. is seams that you're sending the time to the API in a format that it doesn't accept it. You need to format the string you're sending to the API.
  2. use prop locale="es_ES"

Yup, I agree with @hetmann (thanks for posting).

Regarding the first question, react-native-modal-datetime-picker uses the standard JS date format, so you should be able to format it manually.

Thank you for your answers @hetmann @mmazzarolo but:

  1. OK
  2. The language did not work, I attached the 2 options I tried. I don't know if you see something that is not right?

`//option 1
NSLocale * locale = [[NSLocale alloc] initWithLocaleIdentifier:@"es_ES"];
datePicker.locale = locale;
datePicker.calender = [locale objectForKey:NSLocaleCalender];

//option 2
NSString *currentLanguage = [[NSLocale preferredLanguages] firstObject];
[[UIDatePicker appearance] setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"es_ES"]];`

attached also capture of the device so that you see that it is configured in Spanish, and nothing it keeps showing everything of the package in English
Captura de Pantalla 2019-08-14 a la(s) 3 40 10 p  m

@pixsolution the locale prop is used to render the date/time based on regions, basically it will translate it to Spanish: Monday -> Lunes

The idea is that the DateTimePicker will give you a value and you can format that value based on your needs.

Formatting is done using libraries like this:

Was this page helpful?
0 / 5 - 0 ratings