本文整理汇总了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");
}
示例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");
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例10: TestToEpochValue
public void TestToEpochValue()
{
DateTime time = new DateTime(1977, 4, 4, 6, 0, 0, 0);
Assert.AreEqual(229006800, time.ToEpoch());
}
示例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);
}