Skip to content

Instantly share code, notes, and snippets.

@poychang
Last active January 7, 2019 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poychang/73d93b93fa9d398731582c85a8da49e7 to your computer and use it in GitHub Desktop.
Save poychang/73d93b93fa9d398731582c85a8da49e7 to your computer and use it in GitHub Desktop.
[時間的乘法運算] #dotnet
void Main()
{
DemoMultiplyTimeSpan();
DemoTimePlusMultiplyTimeSpan();
}
// Define other methods and classes here
void DemoMultiplyTimeSpan()
{
var duration = TimeSpan.FromMinutes(1);
duration = TimeSpan.FromTicks(duration.Ticks * 12);
Console.WriteLine(duration);
// 00:12:00
}
void DemoTimePlusMultiplyTimeSpan()
{
var now = DateTimeOffset.Now;
Console.WriteLine(now);
// 1/7/2019 1:40:27 PM +08:00
Console.WriteLine(now + MultiplyTimeSpan(TimeSpan.FromMinutes(1), 12));
// 1/7/2019 1:52:27 PM +08:00
}
TimeSpan MultiplyTimeSpan(TimeSpan duration, double deviation)
{
return TimeSpan.FromTicks((long)Math.Round(duration.Ticks * deviation));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment