0

My application is using sql server a database. I am looking for way if user login from US, then the US time will appear on the website. And if user is from UK then UK standard time should appear,

My question is: is there a way I can get date and time with respect to user's location. I am tracking users' ip address and so I know where the user's location.

Is there any solution I can do this in sql server and C#

2 Answers2

1

I wouldn't depend on the server and IP Adresses to do this. Your user could use a proxy in Japan, while sitting in South Africa.

To get a clients time I'd simply use javascript:

var dateTimeNow = new Date();

Of course, if you are using a desktop client with Winforms or WPF then it is simply DateTime.Now.ToShortTimeString().

Marco
  • 22,856
  • 9
  • 75
  • 124
0

The best approach is, store the transaction related DateTime in UTC format in your DB, and display the DateTime based on the TimeZone in UI. If you want just display the DateTime in UI, use client side script for getting local DateTime.

This answer has more details about storing/retrieving DateTime.

Community
  • 1
  • 1
SelvaS
  • 2,105
  • 1
  • 22
  • 31