当前位置: 首页>>代码示例>>C#>>正文


C# JsDate.GetTimezoneOffset方法代码示例

本文整理汇总了C#中System.JsDate.GetTimezoneOffset方法的典型用法代码示例。如果您正苦于以下问题:C# JsDate.GetTimezoneOffset方法的具体用法?C# JsDate.GetTimezoneOffset怎么用?C# JsDate.GetTimezoneOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.JsDate的用法示例。


在下文中一共展示了JsDate.GetTimezoneOffset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTimezoneOffsetWorks

		public void GetTimezoneOffsetWorks() {
			var dt = new JsDate(0);
			Assert.AreEqual(dt.GetTimezoneOffset(), new JsDate(1970, 0, 1).ValueOf() / 60000);
		}
开发者ID:pdavis68,项目名称:SaltarelleCompiler,代码行数:4,代码来源:JsDateTests.cs

示例2: GetObjectValue

            private object GetObjectValue(IXmlSchemaElementDefinition elementDefinition, XmlNode node)
            {
                XmlNodeList nilNodes = XPath.Evaluate(node, "./@i:nil", prefix => prefix == "i" ? "http://www.w3.org/2001/XMLSchema-instance" : null);
                if (nilNodes.Count == 1 && (nilNodes[0].Value == "true" || nilNodes[0].Value == "1"))
                {
                    return null;
                }

                IXmlSchemaSimpleTypeDefinition simpleTypeDefinition = elementDefinition.Type as IXmlSchemaSimpleTypeDefinition;
                if (simpleTypeDefinition != null)
                {
                    if (node.ChildNodes.Count != 1 || node.ChildNodes[0].NodeType != XmlNodeType.Text)
                    {
                        throw new InvalidOperationException("Expected text node as child for element " + elementDefinition.Name + ".");
                    }
                    string text = node.ChildNodes[0].Value;
                    switch (simpleTypeDefinition.Type)
                    {
                        case XmlBuiltInSimpleType.AnyType:
                        case XmlBuiltInSimpleType.AnyUri:
                        case XmlBuiltInSimpleType.Guid:
                        case XmlBuiltInSimpleType.QName:
                        case XmlBuiltInSimpleType.String:
                        case XmlBuiltInSimpleType.Enum:
                            return DecodeString(text);
                        case XmlBuiltInSimpleType.Base64Binary:
                            return StringUtility.FromBase64ToByteArray(text);
                        case XmlBuiltInSimpleType.Boolean:
                            return text == "true" || text == "1";
                        case XmlBuiltInSimpleType.Byte:
                            return FrameworkUtility.ByteTryParse(text);
                        case XmlBuiltInSimpleType.Char:
                            return (int)DecodeString(text)[0];
                        case XmlBuiltInSimpleType.Decimal:
                            return FrameworkUtility.DecimalTryParse(text);
                        case XmlBuiltInSimpleType.Double:
                            return FrameworkUtility.DoubleTryParse(text);
                        case XmlBuiltInSimpleType.Float:
                            return FrameworkUtility.FloatTryParse(text);
                        case XmlBuiltInSimpleType.Int:
                            return FrameworkUtility.IntTryParse(text);
                        case XmlBuiltInSimpleType.Long:
                            return FrameworkUtility.LongTryParse(text);
                        case XmlBuiltInSimpleType.Short:
                            return FrameworkUtility.ShortTryParse(text);
                        case XmlBuiltInSimpleType.UnsignedByte:
                            return FrameworkUtility.ByteTryParse(text);
                        case XmlBuiltInSimpleType.UnsignedInt:
                            return FrameworkUtility.IntTryParse(text);
                        case XmlBuiltInSimpleType.UnsignedLong:
                            return FrameworkUtility.LongTryParse(text);
                        case XmlBuiltInSimpleType.UnsignedShort:
                            return FrameworkUtility.ShortTryParse(text);
                        case XmlBuiltInSimpleType.DateTime:
                            string[] bits = text.Split(new Regex("[-T:+]", "g"));
                            int timeZoneStart;
                            int milliseconds;
                            if (bits.Length == 9)
                            {
                                timeZoneStart = 7;
                                milliseconds = FrameworkUtility.IntTryParse(bits[6]) ?? 0;
                            }
                            else
                            {
                                timeZoneStart = 6;
                                milliseconds = 0;
                            }
                            JsDate dateTime = new JsDate(int.Parse(bits[0]), int.Parse(bits[1]) - 1, int.Parse(bits[2]), int.Parse(bits[3]), int.Parse(bits[4]), int.Parse(bits[5]), milliseconds);
                            int offsetMinutes = int.Parse(bits[timeZoneStart])*60 + int.Parse(bits[timeZoneStart + 1]);
                            bool offsetIsNegative = new Regex("-\\d\\d:\\d\\d$").Test(text);
                            if (offsetIsNegative)
                            {
                                offsetMinutes *= -1;
                            }
                            dateTime.SetMinutes(dateTime.GetMinutes() - offsetMinutes - dateTime.GetTimezoneOffset());
                            return (DateTime)dateTime;
                        case XmlBuiltInSimpleType.Duration:
                            Regex regex = new Regex("([-+]?)P(([0-9]*)Y)?(([0-9]*)M)?(([0-9]*)D)?(T(([0-9]*)H)?(([0-9]*)M)?(([0-9.]*)S)?)?");
                            RegexMatch match = regex.Exec(text);
                            bool durationIsNegative = match[1] == "-";
                            int durationYears = match[3] == null ? 0 : FrameworkUtility.IntTryParse(match[3]) ?? 0;
                            int durationMonths = match[5] == null ? 0 : FrameworkUtility.IntTryParse(match[5]) ?? 0;
                            if (durationYears != 0 || durationMonths != 0)
                            {
                                throw new InvalidOperationException("Durations may not contain years or months.");
                            }
                            int durationDays = match[7] == null ? 0 : FrameworkUtility.IntTryParse(match[7]) ?? 0;
                            int durationHours = match[10] == null ? 0 : FrameworkUtility.IntTryParse(match[10]) ?? 0;
                            int durationMinutes = match[12] == null ? 0 : FrameworkUtility.IntTryParse(match[12]) ?? 0;
                            double durationFractionalSeconds = match[14] == null ? 0 : FrameworkUtility.DoubleTryParse(match[14]) ?? 0;
                            int durationSeconds = Math.Truncate(durationFractionalSeconds);
                            int durationMilliseconds = Math.Truncate(durationFractionalSeconds*1000)%1000;
                            if (durationIsNegative)
                            {
                                durationDays *= -1;
                                durationHours *= -1;
                                durationMinutes *= -1;
                                durationSeconds *= -1;
                                durationMilliseconds *= -1;
                            }
//.........这里部分代码省略.........
开发者ID:jam40jeff,项目名称:CsJs,代码行数:101,代码来源:SoapClient.cs


注:本文中的System.JsDate.GetTimezoneOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。