views:

126

answers:

1

Hi

I am looking to use this plugin: http://keith-wood.name/countdown.html

but I need to use the TimeZone feature of it. So I was looking at the sample code

$('#sydneyCountdown').countdown({until: liftoffTime, timezone: +10});

so +10 is the TimeOffSet number. Now I need to make it so I can do a jquery get request and grab the TimeOffSet from the server(which gets the users time from the db and does TimeOffSet).

However it seems that C# TimeOffSet returns something like this "+02:00"(not this is just a random zone not the same as the one in the jquery example).

So it seems like all the C# TimeOffSet follow that format +/-xx:xx

So I don't understand why the jquery plugin is only 2 digts while the other one is 4 digits.

Can I know off safley the last 2 digits in the C# tomatch the plugin format?

Edit - would this work?

            // working on how to get offsetTime will be posted soon.
            string time = "-08:30";      
            string[] split = new string[] {":"};
            string[] splited = time.Split(split, StringSplitOptions.RemoveEmptyEntries);
            int hours = Convert.ToInt32(splited[0]);
            int mins = Convert.ToInt32(splited[1]);
            int totalMins = (hours * 60) + mins;

So just convert the hours to mins and then add the mins to it?

Edit - With offSetTime

   var info = TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time");
    TimeSpan span  = info.BaseUtcOffset;
    string time = Convert.ToString(span);
    string[] split = new string[] {":"};
    string[] splited = time.Split(split, StringSplitOptions.RemoveEmptyEntries);
    int hours = Convert.ToInt32(splited[0]);
    int mins = Convert.ToInt32(splited[1]);
    int totalMins = (hours * 60) + mins;

Problem though OffSet only gives me the number not the +/- sign. So I don't know how to get it.

Edit -

Never mind I it makes sense that they don't add the plus sign since I was just testing one that would have a "-" sign and it is shown.

A: 

The plugin says:

Cater for time zones with the timezone setting, which is set to the target time's offset from GMT, in either hours or minutes.

So, I think based on the magnitude of the timezone value, it treats it either as hours or minutes. You should convert the <sign><hh>:<mm> format to into number of minutes, to account for timezones that are not hour-aligned. Something like:

var tz = "-08:30";
var tz_tokens = /([+\-])0?(\d+):(\d+)/.exec(tz);
var tz_minutes = (tz_tokens[1] + 1) * (tz_tokens[2] * 60 + tz_tokens[3]);

// ..., timezone: tz_minutes, ...
Ates Goral
Does anyone have a suggestion for a quicker way to convert the tz string to minutes? Make sure you account for "08" being treated as an invalid octal literal.
Ates Goral
it also has something for UTC what if I am not mistaken is what the C# TimeZoneInfo uses?
chobo2
hmm I don't even understand what that is doing. I am not very good with javascript.
chobo2
I also probably would do this all in C# and send over the final number. I have to do a ajax request anyways so might as well use C# to send a final result over and not just a number that I have to then convert to get whatever is needed.
chobo2
Yes! Doing the conversion to minutes in C# would be even better!
Ates Goral
What I just posted will that work?
chobo2