I am using asp.net with C#. and my web server is located in USA, i am in INDIA,
I am executing the following query on click of a button.
INSERT INTO LogTable(LogTime)
BUt after executing this query from my application when i see my data in the sql table then it shows date and time according to my web server time. that i d't want, I want it should display date and time accoridng to India Standard TimeZone. So how to set
a time zone at runtime so that it will take the indian standard time.
Please provide me the code for doing this, I have tried to do this using TimeZone class but not able to understand how to do this,
Wamba {WamBlog}Dont forget to click "Mark as Answer" on the post that helped you.
This credits the member,earns you a point & marks your thread as Resolved.
Page.culture (what it will set) will it change the language of my page??? or what, or if it will change only the time format then it will be for that page and for that time only or it will be for the whole application.
I just want to change the time in Indian Standard only for the time when my query executes so that it will take the time accroding to india, but after that i want everything will run accoridng to web servers time.??????
I suppose that data in sqlServer is stored as Datetime. After you read it you have a datetime variable in your procedure so you can do something like this:
DateTime A = (DateTime)DT["MyDate"];System.Globalization.CultureInfo
CI = new System.Globalization.CultureInfo("YourCultureInfoCode");
Wamba {WamBlog}Dont forget to click "Mark as Answer" on the post that helped you.
This credits the member,earns you a point & marks your thread as Resolved.
can anyone tell me what will be the culture code for india, i want Indian Time zone with English language, but i have seen in the list there is no option of en-INdia, there are HINDI-INDIA but i d't want to display my dat e in hindi language,
You need to format your date each time, but you can place method in a central postition like in a inheritable class or a masterpage. You can use english culture for day name or else.
Wamba {WamBlog}Dont forget to click "Mark as Answer" on the post that helped you.
This credits the member,earns you a point & marks your thread as Resolved.
prashant_vic...
Participant
1155 Points
437 Posts
setting proper TimeZone in ASP.NET with C#
May 20, 2008 08:24 AM|LINK
Hi,
I am using asp.net with C#. and my web server is located in USA, i am in INDIA,
I am executing the following query on click of a button.
INSERT INTO LogTable(LogTime)
BUt after executing this query from my application when i see my data in the sql table then it shows date and time according to my web server time. that i d't want, I want it should display date and time accoridng to India Standard TimeZone. So how to set a time zone at runtime so that it will take the indian standard time.
Please provide me the code for doing this, I have tried to do this using TimeZone class but not able to understand how to do this,
Thanks.
Wamba
Member
404 Points
72 Posts
Re: setting proper TimeZone in ASP.NET with C#
May 20, 2008 08:50 AM|LINK
hi,
All you need to do is to use localization. Take a look to this post: http://forums.asp.net/p/1226341/2203946.aspx and to CultureInfo. You can also force cultureinfo in a page using Page.Culture http://msdn.microsoft.com/en-us/library/system.web.ui.page.culture.aspx (sorry I dont' know indian code)
Dont forget to click "Mark as Answer" on the post that helped you.
This credits the member,earns you a point & marks your thread as Resolved.
prashant_vic...
Participant
1155 Points
437 Posts
Re: setting proper TimeZone in ASP.NET with C#
May 20, 2008 09:27 AM|LINK
Hi,
Page.culture (what it will set) will it change the language of my page??? or what, or if it will change only the time format then it will be for that page and for that time only or it will be for the whole application.
I just want to change the time in Indian Standard only for the time when my query executes so that it will take the time accroding to india, but after that i want everything will run accoridng to web servers time.??????
Wamba
Member
404 Points
72 Posts
Re: setting proper TimeZone in ASP.NET with C#
May 20, 2008 09:40 AM|LINK
Ah ok, if I have understand what do you wont:
I suppose that data in sqlServer is stored as Datetime. After you read it you have a datetime variable in your procedure so you can do something like this:
DateTime A = (DateTime)DT["MyDate"];System.Globalization.CultureInfo CI = new System.Globalization.CultureInfo("YourCultureInfoCode");string FormattedDate = A.ToString(CI);
Here a list of CultureInfo:http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx
NOTE: Code is not tested (no time)
Dont forget to click "Mark as Answer" on the post that helped you.
This credits the member,earns you a point & marks your thread as Resolved.
prashant_vic...
Participant
1155 Points
437 Posts
Re: setting proper TimeZone in ASP.NET with C#
May 23, 2008 06:45 AM|LINK
hi,
can anyone tell me what will be the culture code for india, i want Indian Time zone with English language, but i have seen in the list there is no option of en-INdia, there are HINDI-INDIA but i d't want to display my dat e in hindi language,
So please tell me what should i do???
Wamba
Member
404 Points
72 Posts
Re: setting proper TimeZone in ASP.NET with C#
May 23, 2008 07:31 AM|LINK
Ok we can try with the last resource: Custom Date Format: {http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx}
You need to format your date each time, but you can place method in a central postition like in a inheritable class or a masterpage. You can use english culture for day name or else.
Dont forget to click "Mark as Answer" on the post that helped you.
This credits the member,earns you a point & marks your thread as Resolved.