0

I've been looking for some weeks and I have not found any optimal solution for this problem:

The date in the red box on the picture should change according to the country location of the user.

Example: For the US -> Thursday, Oct 6 2016, 11:27:59 PM

In my code is fixed the xDateFormat to: "%A, %e.%b %Y, %H:%M:%S" but it should change dynamically as I said before.

enter image description here

I have not found any built-in function in the highcharts documentation http://api.highcharts.com/highstock/tooltip.xDateFormat.

Another solution would be to create my own table with the country formats according to: https://stackoverflow.com/a/9893752. For this I should detect first the IP of the user and the localize the country.

Does anyone has a better idea?

Community
  • 1
  • 1
karlihnos
  • 415
  • 1
  • 7
  • 22
  • You could set global option [`useUTC`](http://api.highcharts.com/highcharts/global.useUTC) to `false` to use client side time in a chart. Please create a demo in JSFiddle if this doesn't help. – Kacper Madej Nov 22 '16 at 13:06

1 Answers1

0

For this particular problem you can use a service, like freegeoip.net or geoplugin.net
For more info, please refer this page

What you have to do is send a request(via XHR or whatever you're using in the backend) along with the user's IP to their service as follows :

freegeoip.net/json/<user-ip> | geoplugin.net/json.gp?ip=<user-ip>

or

You can use Date() object to retrieve the users current day, date, time and post it back to your server to update your app ..

Edit

The problem with IP address is it's not reliable, what if the user is behind a VPN or any other anonymous proxy service like TOR, so the IP address received is not very much of help to you. Perhaps sending the users details(time and location) via setting a header in the request would be more reliable.

Some programmer
  • 301
  • 1
  • 12