This might sound a bit funny but I can't see to figure this out. Recently, I decided to work on a project and targeted country is different from the hosting environment but the application is going to be a time critical application. Something like stock
trading system but not exactly but you get what I mean.
My question is - i.e. in my code if I were to do DateTime.Now() , I am pretty sure it would give me the time of the web hosting country (U.S) but not the other country (Let's say China). How would I go about and achieve so that whenever I use DateTime.Now()
in my code, it would give me the current date and time of China instead of U.S ?
Appreciated if anyone could tell me. Thanks.
P.S I'm looking to go for discountasp.net for this project and I guess that's gonna be shared hosting.
Thank you and I have to admit it is very smart but I believe there might be a more like .NET solution to this problem rather than going for the javascript tweak. Imagine if it is a time critical application like stock trading system and I can easily fool
the system by changing my local computer's date and time, then do something. That is just my imgaination but I guess that kind of exploit can be easily done with that tweak. In my script, I use a lot of GETDATE() on the SQL side too.
Would appreciate if I would receive more input and solutions on the matter. Thanks all !
I found the fix for my problem. It might not be the right solution but using UTC time method works for me. Figure out what is your targeted users country and then figure out how many minutes you need to add or subtract from the UTC time and insert it into
the database. Thanks.
Marked as answer by harrylynn on Jan 19, 2013 02:32 PM
harrylynn
Member
284 Points
294 Posts
Web Hosting in different timezone for different country
Jan 18, 2013 10:07 AM|LINK
Hi Everyone,
This might sound a bit funny but I can't see to figure this out. Recently, I decided to work on a project and targeted country is different from the hosting environment but the application is going to be a time critical application. Something like stock trading system but not exactly but you get what I mean.
My question is - i.e. in my code if I were to do DateTime.Now() , I am pretty sure it would give me the time of the web hosting country (U.S) but not the other country (Let's say China). How would I go about and achieve so that whenever I use DateTime.Now() in my code, it would give me the current date and time of China instead of U.S ?
Appreciated if anyone could tell me. Thanks.
P.S I'm looking to go for discountasp.net for this project and I guess that's gonna be shared hosting.
prabu.raveen...
Contributor
5020 Points
955 Posts
Re: Web Hosting in different timezone for different country
Jan 18, 2013 11:31 AM|LINK
use javascript to get the timezone and assign value to a hidden variable,
<script type='text/javascript'>
var now = new Date();
document.getElementById('hiddenfield').value = now.getTimezoneOffset();
</script>
use this hidden field in your asp.net code behind
harrylynn
Member
284 Points
294 Posts
Re: Web Hosting in different timezone for different country
Jan 18, 2013 05:33 PM|LINK
Thank you and I have to admit it is very smart but I believe there might be a more like .NET solution to this problem rather than going for the javascript tweak. Imagine if it is a time critical application like stock trading system and I can easily fool the system by changing my local computer's date and time, then do something. That is just my imgaination but I guess that kind of exploit can be easily done with that tweak. In my script, I use a lot of GETDATE() on the SQL side too.
Would appreciate if I would receive more input and solutions on the matter. Thanks all !
harrylynn
Member
284 Points
294 Posts
Re: Web Hosting in different timezone for different country
Jan 18, 2013 09:49 PM|LINK
I found the fix for my problem. It might not be the right solution but using UTC time method works for me. Figure out what is your targeted users country and then figure out how many minutes you need to add or subtract from the UTC time and insert it into the database. Thanks.