microsoft/healthcare-shared-components

Public

mirrored from https://github.com/microsoft/healthcare-shared-componentsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
main

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Microsoft.Health.Core/Extensions/DateTimeExtensions.cs

21lines · modepreview

// -------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// -------------------------------------------------------------------------------------------------

using System;

namespace Microsoft.Health.Core.Extensions;

public static class DateTimeExtensions
{
    /// <summary>
    /// Truncates a DateTime to millisecond precision
    /// </summary>
    /// <param name="dateTime">The DateTime</param>
    /// <returns>The truncated dateTime</returns>
    public static DateTime TruncateToMillisecond(this DateTime dateTime)
    {
        return new DateTime(dateTime.Ticks / TimeSpan.TicksPerMillisecond * TimeSpan.TicksPerMillisecond, dateTime.Kind);
    }
}