Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
3568 Widoki

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)

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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.


Awatar
Odrzuć

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.

Najlepsza odpowiedź

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"

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
gru 19
9666
1
maj 16
4519
2
mar 23
10702
0
lis 22
2296
0
wrz 21
2769