跳至内容
菜单
此问题已终结
1 回复
1628 查看

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

形象
丢弃