我需要像标题一样转换为自1970年以来的几周和一年。我只有一周和一年的信息发生了一些事件。周一的一周明星。我认为DateTime不是答案,因为它无法处理一年的一周。我需要的是类似于方法双getMili(int week, int year)
。谢谢
您可以这样说:
// Let's convert 15th Monday in 2014
int MondaysNumber = 15;
DateTime source = new DateTime(2014, 1, 1);
int delta = 7 + DayOfWeek.Monday - source.DayOfWeek;
if (delta >= 7)
delta -= 7;
source = source.AddDays((MondaysNumber - 1) * 7 + delta);
// Finally, convert it into milliseconds
Double result = (source - new DateTime(1970, 1, 1)).TotalMilliseconds;