Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
3617 Lượt xem

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)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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.


Ảnh đại diện
Huỷ bỏ

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.

Tác giả

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.

Câu trả lời hay nhất

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"

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 19
9711
1
thg 5 16
4568
2
thg 3 23
10757
0
thg 11 22
2343
0
thg 9 21
2780