콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
3566 화면

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)

아바타
취소
베스트 답변

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

아바타
취소
작성자 베스트 답변

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.


아바타
취소

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.

작성자

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.

베스트 답변

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"

아바타
취소
관련 게시물 답글 화면 활동
1
12월 19
9665
1
5월 16
4516
2
3월 23
10702
0
11월 22
2296
0
9월 21
2767