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


C# Duration.ToString方法代码示例

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


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

示例1: DefaultValues

		public void DefaultValues ()
		{
			Duration d = new Duration ();
			Assert.AreEqual (false, d.HasTimeSpan, "HasTimeSpan");
			Assert.Throws<InvalidOperationException> (() => { object o = d.TimeSpan; GC.KeepAlive(o); }, "TimeSpan");
			Assert.AreEqual ("Automatic", d.ToString (), "ToString");
		}
开发者ID:dfr0,项目名称:moon,代码行数:7,代码来源:DurationTest.cs

示例2: TestDurationClass

        public void TestDurationClass()
        {
            var firstDuration = new Duration(200, TimeUnit.Minutes);
            
            Check.That(firstDuration.RawDuration).IsEqualTo(200);
            Check.That(firstDuration.Unit).IsEqualTo(TimeUnit.Minutes);
            Check.That(firstDuration.ToString()).IsEqualTo("200 Minutes");
            Check.That(firstDuration > new Duration(100, TimeUnit.Seconds)).IsTrue();
            Check.That(firstDuration < new Duration(100, TimeUnit.Hours)).IsTrue();

            var anotherDurationWithSameValue = new Duration(200, TimeUnit.Minutes);

            // test objects override
            Check.That(firstDuration.GetHashCode()).IsEqualTo(anotherDurationWithSameValue.GetHashCode());
            Check.That(firstDuration).IsEqualTo(anotherDurationWithSameValue);
            Check.That(anotherDurationWithSameValue.Equals(firstDuration)).IsTrue();
            Check.That(anotherDurationWithSameValue == firstDuration).IsTrue();
            Check.That(anotherDurationWithSameValue.Equals(null)).IsFalse();
            Check.That(anotherDurationWithSameValue.Equals(20)).IsFalse();
            Check.That(anotherDurationWithSameValue.Equals((object)firstDuration)).IsTrue();
        }
开发者ID:dirkrombauts,项目名称:NFluent,代码行数:21,代码来源:DurationTests.cs

示例3: TestDurationClass

        public void TestDurationClass()
        {
            var test = new Duration(200, TimeUnit.Minutes);

            Assert.AreEqual(200, test.RawDuration);

            Assert.AreEqual(TimeUnit.Minutes, test.Unit);

            Assert.AreEqual("200 Minutes", test.ToString());

            Assert.IsTrue(test > new Duration(100, TimeUnit.Seconds));
            Assert.IsTrue(test < new Duration(100, TimeUnit.Hours));

            var altDuration = new Duration(200, TimeUnit.Minutes);

            // test objects override
            Assert.AreEqual(altDuration.GetHashCode(), test.GetHashCode());
            Assert.AreEqual(altDuration, test);
            Assert.IsTrue(altDuration.Equals(test));
            Assert.IsTrue(altDuration == test);
            Assert.IsFalse(altDuration.Equals(null));
            Assert.IsFalse(altDuration.Equals(20));
            Assert.IsTrue(altDuration.Equals((object)test));
        }
开发者ID:rhwy,项目名称:NFluent,代码行数:24,代码来源:TimeHelperTest.cs

示例4: Main


//.........这里部分代码省略.........
            Console.WriteLine("2004-03-14T10:25:31.98Z = {0:d} {0:HH:mm:ss.fff}",
                DateUtils.FromISO8601String("2004-03-14T10:25:31.98Z", true));
            Console.WriteLine("2004-03-14T10:25:31-04 = {0}",
                DateUtils.FromISO8601String("2004-03-14T10:25:31-04", true));
            Console.WriteLine("2004-03-14T10:25:31+08:30 = {0}",
                DateUtils.FromISO8601String("2004-03-14T10:25:31+08:30", true));

            TimeSpan ts = DateUtils.FromISO8601TimeZone("+08");

            Console.WriteLine("\n+08 = {0} hours {1} minutes", ts.Hours, ts.Minutes);

            ts = DateUtils.FromISO8601TimeZone("-08");

            Console.WriteLine("-08 = {0} hours {1} minutes", ts.Hours, ts.Minutes);

            ts = DateUtils.FromISO8601TimeZone("-0830");

            Console.WriteLine("-0830 = {0} hours {1} minutes", ts.Hours, ts.Minutes);

            ts = DateUtils.FromISO8601TimeZone("+08:30");

            Console.WriteLine("+08:30 = {0} hours {1} minutes", ts.Hours, ts.Minutes);

            // Pause to review output
            Console.WriteLine("Press ENTER to continue");
            Console.ReadLine();

            // Test the Duration class
            Console.WriteLine("Assumptions: 1 year = {0} days, 1 month = {1} days\n", Duration.DaysInOneYear,
                Duration.DaysInOneMonth);

            Duration d = new Duration("P1Y2M3W4DT5H6M7S");

            Console.WriteLine("P1Y2M3W4DT5H6M7S = {0}", d.ToString());
            Console.WriteLine("P1Y2M3W4DT5H6M7S = {0} (max units = months)", d.ToString(Duration.MaxUnit.Months));

            d = new Duration("P10Y11MT16M12S");

            Console.WriteLine("P10Y11MT16M12S = {0}", d.ToString());

            d = new Duration("P5M2DT16M");

            Console.WriteLine("P5M2DT16M = {0}", d.ToString());

            d = new Duration("P7W");

            Console.WriteLine("P7W = {0}", d.ToString());
            Console.WriteLine("P7W = {0} (max units = weeks)", d.ToString(Duration.MaxUnit.Weeks));
            Console.WriteLine("P7W = {0} (max units = days)", d.ToString(Duration.MaxUnit.Days));

            d = new Duration("P7W2D");

            Console.WriteLine("P7W2D = {0}", d.ToString());
            Console.WriteLine("P7W2D = {0} (max units = weeks)", d.ToString(Duration.MaxUnit.Weeks));
            Console.WriteLine("P7W2D = {0} (max units = days)", d.ToString(Duration.MaxUnit.Days));

            d = new Duration("P5DT2S");

            Console.WriteLine("P5DT2S = {0}", d.ToString());

            d = new Duration("PT24H");

            Console.WriteLine("PT24H = {0}", d.ToString());
            Console.WriteLine("PT24H = {0} (max units = hours)", d.ToString(Duration.MaxUnit.Hours));
            Console.WriteLine("PT24H = {0} (max units = minutes)", d.ToString(Duration.MaxUnit.Minutes));
            Console.WriteLine("PT24H = {0} (max units = seconds)",  d.ToString(Duration.MaxUnit.Seconds));
开发者ID:modulexcite,项目名称:PDI,代码行数:67,代码来源:PDIDatesTest.cs


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