Skip to content
The Chat Archive
gpt-3.5-turbo-0301· OpenAI WildChat-4.8M (AI2)

C# 获取当前时间转为13位时间戳

  1. User

    C# 获取当前时间转为13位时间戳

  2. Assistant

    可以使用以下代码:

    DateTime now = DateTime.Now;
    long timestamp = (long)((now - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds);
    

    首先获取当前时间 now,然后将其与 UTC 时间的 1970 年 1 月 1 日 0 点 0 分 0 秒相减得到一个 TimeSpan,再将其转换为毫秒数,并转换为 long 类型,就得到了当前时间的 13 位时间戳 timestamp。