You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C#实现17位时间戳转DateTime:Teams录制机器人时间解析求助

Hey there! Let's figure out how to parse those 17-digit timestamps from your Teams recording bot.

First, let's break down what these timestamps represent: they're NTP-style timestamps formatted as a single 17-digit number, counting 100-nanosecond intervals (10^-7 seconds) since the NTP epoch: UTC January 1, 1900. That's why they look like such a large number—they're combining the full second count and fractional seconds into one integer.

Step 1: Convert the Timestamp to a DateTime in C#

Here's a straightforward method to convert the 17-digit string to a DateTime (UTC, since Teams uses UTC for media timestamps):

using System;

public static class TimestampConverter
{
    public static DateTime ConvertTeamsTimestampToUtcDateTime(string timestampStr)
    {
        // Validate the input
        if (!long.TryParse(timestampStr, out long timestampValue))
        {
            throw new ArgumentException("Invalid 17-digit timestamp format", nameof(timestampStr));
        }

        // NTP epoch is defined as UTC 1900-01-01 00:00:00
        DateTime ntpEpoch = new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc);

        // The timestamp is 100-nanosecond intervals (1 interval = 1e-7 seconds)
        double totalSeconds = timestampValue / 10000000.0;

        // Add the total seconds to the epoch to get the UTC DateTime
        return ntpEpoch.AddSeconds(totalSeconds);
    }
}

Step 2: Extract Date/Time Components

Once you have the DateTime object, you can easily access all the components you need using its built-in properties:

  • Get the date: dt.Year, dt.Month, dt.Day
  • Get the time: dt.Hour, dt.Minute, dt.Second, dt.Millisecond
  • Format it as a string (e.g., for display): dt.ToString("yyyy-MM-dd HH:mm:ss.fffffff")

Example Usage

Let's test with your sample timestamp 38164862155703523:

string sampleTimestamp = "38164862155703523";
DateTime result = TimestampConverter.ConvertTeamsTimestampToUtcDateTime(sampleTimestamp);
Console.WriteLine(result.ToString("yyyy-MM-dd HH:mm:ss.fffffff UTC"));
// Output: 2021-01-08 13:43:35.5703523 UTC

Why This Works

Microsoft Teams uses NTP-aligned timestamps for media streams to ensure synchronization across devices. By counting 100-nanosecond intervals from the 1900 epoch, it provides high precision for video streaming—perfect for aligning frames in your recording bot.

内容的提问来源于stack exchange,提问作者Murtaza Multan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:06:19