summary refs log tree commit diff
path: root/crypto/src/util/date/DateTimeUtilities.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/util/date/DateTimeUtilities.cs')
-rw-r--r--crypto/src/util/date/DateTimeUtilities.cs28
1 files changed, 27 insertions, 1 deletions
diff --git a/crypto/src/util/date/DateTimeUtilities.cs b/crypto/src/util/date/DateTimeUtilities.cs
index 3660e29c2..c46cde8db 100644
--- a/crypto/src/util/date/DateTimeUtilities.cs
+++ b/crypto/src/util/date/DateTimeUtilities.cs
@@ -53,5 +53,31 @@ namespace Org.BouncyCastle.Utilities.Date
 		{
 			return DateTimeToUnixMs(DateTime.UtcNow);
 		}
-	}
+
+        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);
+        }
+
+        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);
+        }
+
+        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);
+        }
+
+        public static DateTime WithPrecisionSecond(DateTime dateTime)
+        {
+            return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,
+                dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Kind);
+        }
+    }
 }