diff options
Diffstat (limited to 'crypto/src/util/date')
-rw-r--r-- | crypto/src/util/date/DateTimeUtilities.cs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/crypto/src/util/date/DateTimeUtilities.cs b/crypto/src/util/date/DateTimeUtilities.cs index c46cde8db..1105cbdd7 100644 --- a/crypto/src/util/date/DateTimeUtilities.cs +++ b/crypto/src/util/date/DateTimeUtilities.cs @@ -56,28 +56,26 @@ namespace Org.BouncyCastle.Utilities.Date public static DateTime WithPrecisionCentisecond(DateTime dateTime) { - int millisecond = dateTime.Millisecond - (dateTime.Millisecond % 10); - return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, - dateTime.Hour, dateTime.Minute, dateTime.Second, millisecond, dateTime.Kind); + long ticks = dateTime.Ticks - dateTime.Ticks % (TimeSpan.TicksPerMillisecond * 10L); + return new DateTime(ticks, dateTime.Kind); } public static DateTime WithPrecisionDecisecond(DateTime dateTime) { - int millisecond = dateTime.Millisecond - (dateTime.Millisecond % 100); - return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, - dateTime.Hour, dateTime.Minute, dateTime.Second, millisecond, dateTime.Kind); + long ticks = dateTime.Ticks - dateTime.Ticks % (TimeSpan.TicksPerMillisecond * 100L); + return new DateTime(ticks, dateTime.Kind); } public static DateTime WithPrecisionMillisecond(DateTime dateTime) { - return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, - dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond, dateTime.Kind); + long ticks = dateTime.Ticks - dateTime.Ticks % TimeSpan.TicksPerMillisecond; + return new DateTime(ticks, dateTime.Kind); } public static DateTime WithPrecisionSecond(DateTime dateTime) { - return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, - dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Kind); + long ticks = dateTime.Ticks - dateTime.Ticks % TimeSpan.TicksPerSecond; + return new DateTime(ticks, dateTime.Kind); } } } |