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


C# DateTime.ToEpoch方法代码示例

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


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

示例1: ToEpochTest_BeforeEpochStart

        public void ToEpochTest_BeforeEpochStart()
        {
            // Arrange
            var date = new DateTime(1969, 12, 31, 23, 59, 59);

            // Act 
            var epoch = date.ToEpoch();

            // Assert 
            epoch.Should().Be(-1, "one second less than epoch start");
        }
开发者ID:smiggleworth,项目名称:Stripe.Client,代码行数:11,代码来源:DateTimeExtensionsTests.cs

示例2: ToEpochTest_EpochStart

        public void ToEpochTest_EpochStart()
        {
            // Arrange
            var date = new DateTime(1970, 1, 1);

            // Act 
            var epoch = date.ToEpoch();

            // Assert 
            epoch.Should().Be(0, "that is when epoch starts");
        }
开发者ID:smiggleworth,项目名称:Stripe.Client,代码行数:11,代码来源:DateTimeExtensionsTests.cs

示例3: DateTime_ToEpoch_Should_Convert_Historical_Epoch_To_Date

        public void DateTime_ToEpoch_Should_Convert_Historical_Epoch_To_Date()
        {
            // arrange
            var pre_epoch_date = new DateTime(1950, 1, 1 , 10, 30, 00);
            var expectedEpoch = -631114200;

            // act
            var target = pre_epoch_date.ToEpoch();

            // assert
            target.Should().Be(expectedEpoch);
        }
开发者ID:hanssens,项目名称:extensions,代码行数:12,代码来源:UnitConverter.DateTime.Tests.cs

示例4: DateTime_ToEpoch_Should_Convert_Epoch_To_Date

        public void DateTime_ToEpoch_Should_Convert_Epoch_To_Date()
        {
            // arrange
            var date = new DateTime(1981, 6, 15 , 20, 30, 00);
            var expectedEpoch = 361485000;

            // act
            var target = date.ToEpoch();

            // assert
            target.Should().Be(expectedEpoch);
        }
开发者ID:hanssens,项目名称:extensions,代码行数:12,代码来源:UnitConverter.DateTime.Tests.cs

示例5: GetTraktEpisodeRateData

        private TraktEpisode GetTraktEpisodeRateData(Dictionary<string,string> episode, TraktShowSummary showSummary)
        {
            if (showSummary == null || showSummary.Seasons == null || showSummary.Seasons.Count == 0)
                return null;

            string episodeTitle = GetEpisodeName(episode[IMDbFieldMapping.cTitle]);

            // find episode title in list of episodes from show summary
            if (!string.IsNullOrEmpty(episodeTitle))
            {
                TraktShowSummary.TraktSeason.TraktEpisode match = null;
                foreach (var season in showSummary.Seasons)
                {
                    if (match != null) continue;
                    match = season.Episodes.FirstOrDefault(e => string.Equals(e.Title, episodeTitle, StringComparison.InvariantCultureIgnoreCase));
                }

                if (match != null)
                {
                    return new TraktEpisode
                                {
                                    Episode = match.Episode,
                                    Season = match.Season,
                                    TVDbId = showSummary.TVDbId,
                                    Title = showSummary.Title,
                                    Year = showSummary.Year,
                                    Rating = int.Parse(episode[IMDbFieldMapping.cRating])
                                };
                }
            }

            // we can also lookup by airDate
            string episodeAirDate = episode[IMDbFieldMapping.cReleaseDate];

            if (!string.IsNullOrEmpty(episodeAirDate))
            {
                // get epoch date
                long dateTimeEpoch = 0;
                try
                {
                    var splitDate = episodeAirDate.Split('-');
                    // parse date and add 8hours for PST
                    DateTime dateTime = new DateTime(int.Parse(splitDate[0]), int.Parse(splitDate[1]), int.Parse(splitDate[2])).AddHours(8);
                    dateTimeEpoch = dateTime.ToEpoch();
                }
                catch
                {
                    UIUtils.UpdateStatus(string.Format("Unable to get info for {0}", episode[IMDbFieldMapping.cTitle]), true);
                    return null;
                }

                TraktShowSummary.TraktSeason.TraktEpisode match = null;
                foreach (var season in showSummary.Seasons)
                {
                    if (match != null) continue;
                    match = season.Episodes.FirstOrDefault(e => e.FirstAired == dateTimeEpoch);
                }

                if (match != null)
                {
                    return new TraktEpisode
                    {
                        Episode = match.Episode,
                        Season = match.Season,
                        TVDbId = match.TVDbId,
                        Title = showSummary.Title,
                        Year = showSummary.Year,
                        Rating = int.Parse(episode[IMDbFieldMapping.cRating])
                    };
                }
            }

            UIUtils.UpdateStatus(string.Format("Unable to get info for {0}", episode[IMDbFieldMapping.cTitle]), true);
            return null;
        }
开发者ID:alzyee,项目名称:TraktRater,代码行数:75,代码来源:IMDb.cs

示例6: DateTime_ToEpoch_Should_Have_Proper_StartDate

        public void DateTime_ToEpoch_Should_Have_Proper_StartDate()
        {
            // arrange
            var date = new DateTime(1970, 1, 1, 0, 0, 0);
            var expectedEpoch = 0;

            // act
            var target = date.ToEpoch();

            // assert
            target.Should().Be(expectedEpoch);
        }
开发者ID:hanssens,项目名称:extensions,代码行数:12,代码来源:UnitConverter.DateTime.Tests.cs

示例7: ToEpoch_pre_Unix

 public void ToEpoch_pre_Unix()
 {
     const long numberOfSecondsUntilBeginningOfUnixEpoch = -86400;
     var dateTime = new DateTime(1969, 12, 31);
     var actual = dateTime.ToEpoch();
     Assert.AreEqual(numberOfSecondsUntilBeginningOfUnixEpoch, actual);
 }
开发者ID:BWortman,项目名称:DotNetExtensions,代码行数:7,代码来源:DateTimeExtensionsTests.cs

示例8: ToEpoch_post_Unix

 public void ToEpoch_post_Unix()
 {
     const long numberOfSecondsSinceBeginningOfUnixEpoch = 432000;
     var dateTime = new DateTime(1970, 1, 6);
     var actual = dateTime.ToEpoch();
     Assert.AreEqual(numberOfSecondsSinceBeginningOfUnixEpoch, actual);
 }
开发者ID:BWortman,项目名称:DotNetExtensions,代码行数:7,代码来源:DateTimeExtensionsTests.cs

示例9: ToEpoch_returns_expected_result

 public long ToEpoch_returns_expected_result(int year, int month, int day, int hour, int minute, int second, int ms)
 {
     var dateTime = new DateTime(year, month, day, hour, minute, second, ms);
     var epoch = dateTime.ToEpoch();
     return epoch;
 }
开发者ID:jarrettmeyer,项目名称:portfolio-mvc,代码行数:6,代码来源:DateTimeExtensionsTests.cs

示例10: TestToEpochValue

        public void TestToEpochValue()
        {
            DateTime time = new DateTime(1977, 4, 4, 6, 0, 0, 0);

            Assert.AreEqual(229006800, time.ToEpoch());
        }
开发者ID:nicklv,项目名称:SharpOAuth2,代码行数:6,代码来源:EpochTests.cs

示例11: EpochDate

        public void EpochDate()
        {
            var date = new DateTime(2010, 1, 1);
            long result;
            result = date.ToEpoch();

            var result2 = result.FromEpoch();
            Assert.AreEqual(2010, result2.Year);
            Assert.AreEqual(1, result2.Day);
            Assert.AreEqual(1, result2.Month);
        }
开发者ID:cityindex-attic,项目名称:ciapi-oauth2-service,代码行数:11,代码来源:UtilitiesFixture.cs


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