Last active
January 7, 2019 05:43
-
-
Save poychang/73d93b93fa9d398731582c85a8da49e7 to your computer and use it in GitHub Desktop.
[時間的乘法運算] #dotnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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