1

I'm using Ajax Control Kit in a web application. The issue is when I access the application with India Time Zone then It's working fine but when I choose the time zone of Central Time (US and Canada) the calendar shows display date as Selected Date-1. For example, If I choose 16.Oct.2012 it'll display(in extendar control) as 15.Oct.2012. I tried the following code but of no help:

protected void Page_Load(object sender, EventArgs e) {
    string Lang = "en-US"; //set your culture here
    System.Threading.Thread.CurrentThread.CurrentCulture =
        new System.Globalization.CultureInfo(Lang);
}

EnableScriptGlobalization = "true";

Also During debugging i find that sender for the Javascript function itself stores the wrong value, i.e., date which is = selected date-1

function setDateIntoHiddenField(sender, args)

Any ideas or suggestions ?

ABCD
  • 249
  • 1
  • 4
  • 17

3 Answers3

2

Why are you trying with romanian culture? Try with US culture like:

string Lang = "en-US"; //set your culture here
System.Threading.Thread.CurrentThread.CurrentCulture =
new System.Globalization.CultureInfo(Lang);

Central time is UTC -5

Romanian time is UTC+2

Set datepicker value like this:

DateTime.UtcNow

You can find deeper instruction here about using timezones: How to elegantly deal with timezones

Community
  • 1
  • 1
speti43
  • 2,886
  • 1
  • 20
  • 23
  • Thanks for the info but the suggestion does not work for me. i have also updated the question. – ABCD Oct 17 '12 at 13:55
  • One more question, this DateTime.UtcNow should be added during creating controls i believe. – ABCD Oct 17 '12 at 14:33
  • After you have created the control set the SelectedDate property. Like this: DatePicker1.SelectedDate = DateTime.UtcNow; – speti43 Oct 17 '12 at 14:37
1

You already got a good advice that you should use UTC date value instead of local.

When you setting SelectedDate value it considered by Calendar extender control as an UTC date, so if you set 16.Oct.2012 selected date value it's means that you have set Tue, 16 Oct 2012 00:00:00 GMT and when this value converted to local Central Time, it's still 15th October in Central Time zone. Strictly saying it's 10/15/2012 7:00:00 PM.

BTW, you may try to set 16.Oct.2012 23:00 selected date value and check shown date for India region. I promise that you'll be surprised.

Yuriy Rozhovetskiy
  • 22,270
  • 4
  • 37
  • 68
1

You can try following code to have UTC date on Client Side

 var localDate = sender.get_selectedDate(); 
    var dateTime = new Date(localDate.getUTCFullYear(), localDate.getUTCMonth(), localDate.getUTCDate()).format("MMM dd, yyyy");

Then use dateTime to set the text on the textbox.

Ashwani K
  • 7,880
  • 19
  • 63
  • 102
  • @Saurabh, it's looks like ostrich buried head in the sand. Let's imagine that you developing web application that will be used by users all around a world. And lets imagine that you created a meeting appointment with a distributed team on `16 Oct 2012 16:00` Then users from US will be online for this meeting when it already had gone. – Yuriy Rozhovetskiy Oct 18 '12 at 10:34