有趣的谜题,感谢挑战:)
这应该在 c# 中完成。几乎可以肯定会瘦身,但它的冗长足以解释发生了什么。
// Initialise with date the event started, and frequency
DateTime startDate = new DateTime(2009, 8,1,9,0,0);
TimeSpan frequency = new TimeSpan(0, 15, 0);
// Store datetime now (so that it doesnt alter during following calculations)
DateTime now = DateTime.Now;
// Calculate the number of ticks that have occured since the event started
TimeSpan pastTimeSpan = now.Subtract(startDate);
// Divide the period that the event has been running by the frequency
// Take the remaining time span
TimeSpan remainingTimeSpan = new TimeSpan(pastTimeSpan.Ticks % frequency.Ticks);
// Calculate last occurence the event ran
DateTime lastOccurence = now.Subtract(remainingTimeSpan);
// Calculate next occurence the event will run
DateTime nextOccurence = lastOccurence.Add(frequency);