Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
3173 Vistas

I have a project using React Native to FE and Odoo to BE. I'm calling field Date from odoo by Graphql, and when I test in Graphiql:  "dateOfBirth": 738733". I want to convert that day to 'dd/mm/yy' in React Native (DateTimePicker).


The expected result: 08/01/2023 (mm/dd/yyyy)

Avatar
Descartar
Mejor respuesta

How do implement dynamic form in react native using odoo? please help

Avatar
Descartar
Autor Mejor respuesta

Thanks for your help. I tried, but the result was not as expected. 

My result: 09/01/1970 (mm/dd/yyyy). 

I used moment in React to format before, but the result was 09/01/1970 (like this way). 

Please.


Avatar
Descartar

If you're getting the Unix timestamp as 738733 from Odoo GraphQL and you expect it to represent 08/01/2023 (August 1, 2023), then there seems to be a discrepancy in the timestamps you're receiving. The provided timestamp and the expected date don't match.

Make sure that you are correctly receiving and processing the timestamp from Odoo's GraphQL response. If the timestamp is indeed meant to represent 08/01/2023, then you need to verify how the timestamp is generated and transmitted in your Odoo setup.

For reference, if you have a valid Unix timestamp for 08/01/2023, it would be a much larger number than 738733, typically in the order of billions (seconds since January 1, 1970). Double-check the data you are receiving and consider checking with the Odoo API or your backend to ensure that the correct timestamp is being sent to your React Native application.

Autor

I checked my field date_of_birth and it was 'field.Date'. Then I changed to 'field.Datetime' and used your way to convert the timestamp, and it's working.

Thanks a lot.

Mejor respuesta

try this way:
// Assuming date of birth is the timestamp received from Odoo

const timestamp = 738733; // Replace this with the actual timestamp


// Convert the timestamp to a JavaScript Date object

const date = new Date(timestamp * 1000); // Odoo timestamp is in seconds, so convert to milliseconds


// Format the date as 'dd/mm/yy'

const formattedDate = `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear().toString().slice(-2)}`;


console.log(formattedDate); // Output: "18/02/23"

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
dic 19
9494
1
may 16
4308
2
mar 23
10427
0
nov 22
2101
0
sept 21
2632