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

Hello

During checkout of a user I plan to use the local-time of the logged-in user for validation of a field. Now I have the problem, that I cannot get the local-time of the user. I only get the server-time in UTC. To display the users time I tried it like that in qweb-report:

<span t-esc="datetime.datetime.now().astimezone()"/>

Can someone help how to convert the time displayed to users local time or just convert it from UTC to CET?

Thanks

René

아바타
취소
베스트 답변

We can determine user location in 2 ways.


1. user IP address to determine user timezone and other info using ipinfo.


$ curl https://ipinfo.io/27.116.51.143


{

"ip": "27.116.51.143",

"city": "Gandhinagar",

"region": "Gujarat",

"country": "IN",

"loc": "23.2167,72.6833",

"org": "AS45916 Gujarat Telelink Pvt Ltd",

"postal": "382042",

"timezone": "Asia/Kolkata",

"readme": "https://ipinfo.io/missingauth"

}


2. Find timezone using the GeoIP package. This package you can install on your server. If you want to know how to install you can refer https://kanakinfosystems.com/blog/how-to-show-geolocation-based-pricelist post.


Python:

print('GeoIP Info_____', request.session.get('geoip'))


Result:

{

'city': 'Gandhinagar',

'country_code': 'IN',

'country_name': 'India',

'region': 'GJ',

'time_zone': 'Asia/Kolkata'

}

For more information Contact us: -  https://kanakinfosystems.com/odoo-development-services

아바타
취소