Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to pick Indian DateTime in my website. Locally it's getting correct date, But if I upload it to Server then it is getting different date, Because Server is in USA. So it is getting USA DateTime in text.

Here I want to get Indian DateTime in that textbox. So How Can I fix this problem?

I tried many ways but i din't get.

DateTime.UtcNow.ToUniversalTime().ToShortDateString()
DateTime.Now.ToUniversalTime().ToShortDateString()

and some other ways. Please help me to solve this problem.


Thanks in Advance
Posted
Updated 8-Nov-13 23:26pm
v2

Place in the header of your source page
<%@ Page %>
your culture Hindi (India) hi-IN
Culture="hi-IN"
 
Share this answer
 
v4
Comments
Aboobakkar Siddeq D U 9-Nov-13 2:21am    
Now I'm Using like this

txtRegDate.Text = DateTime.Now.ToShortDateString();

How Can I change this line to solve my problem please?
[no name] 9-Nov-13 2:24am    
Did you use the culture tag as I suggested up here?
Aboobakkar Siddeq D U 9-Nov-13 2:31am    
No I didn't use anything.
Aboobakkar Siddeq D U 9-Nov-13 2:32am    
I don't how to use? where to use? please help me
[no name] 9-Nov-13 2:34am    
In your source page where .aspx is in the first line where there is the page tag inside it use the culture as I gave you above
I think what you are looking for is something like this.
//use utc time to avoid daylight savings time in us. and use correct number of hours
numberOfHoursToAdd = 7;
private DateTime today = DateTime.Now.AddHours(numberOfHoursToAdd);


Hope this helps.

Edit fixed typo.
 
Share this answer
 
v2
try this.


C#
TimeZoneInfo timzoe = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"); and then 

DateTime indiaTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow,timzoe);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900