【发布时间】:2009-09-16 18:17:05
【问题描述】:
我正在寻找使用这个插件:http://keith-wood.name/countdown.html
但我需要使用它的 TimeZone 功能。所以我在看示例代码
$('#sydneyCountdown').countdown({until: liftoffTime, timezone: +10});
所以 +10 是 TimeOffSet 数字。现在我需要这样做,以便我可以执行 jquery get 请求并从服务器获取 TimeOffSet(它从数据库获取用户时间并执行 TimeOffSet)。
但是,C# TimeOffSet 似乎返回类似“+02:00”的内容(这不仅仅是一个随机区域,与 jquery 示例中的区域不同)。
所以看起来所有 C# TimeOffSet 都遵循这种格式 +/-xx:xx
所以我不明白为什么jquery插件只有2位而另一个是4位。
我可以知道 C# 中的最后 2 位数字以匹配插件格式吗?
编辑 - 这行得通吗?
// 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;
所以只需将小时转换为分钟,然后将分钟添加到其中?
编辑 - 使用 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;
问题虽然 OffSet 只给我数字而不是 +/- 符号。所以我不知道如何获得它。
编辑 -
没关系,他们不添加加号是有道理的,因为我只是在测试一个带有“-”符号并显示出来的符号。
【问题讨论】:
-
int totalMins = (小时 * 60) + 分钟;如果小时数为负数,这将不起作用。您也必须对分钟应用相同的符号。试试: int totalMins = (hours * 60) + mins * Math.Sign(hours);
标签: c# .net asp.net javascript jquery