将本地时间(10 位数字)转换为可读的日期时间格式

发布于 2024-08-25 14:21:38 字数 441 浏览 12 评论 0原文

我正在使用 pbx 进行 VoIP 呼叫。 pbx 的一方面是您可以选择接收 CDR 包。这些包有两个时间戳:“utc”和“local”,但两者似乎总是相同的。

这是时间戳的示例:“1268927156”。

乍一看,似乎没有什么逻辑。于是我尝试了多种方法进行转换,但效果都不好。该值应提供今天上午 11 点 (+1GMT) 左右的时间。

我尝试过的事情:

  • Datetime dt = new Datetime(number);
  • 时间跨度 ts = 新时间跨度(数字);
  • DateTime utc = new DateTime(number + 504911232000000000, DateTimeKind.Utc)

和其他一些我现在不记得了。

我在这里错过了一些愚蠢的事情吗?

提前致谢

I'm working with pbx for voip calls. One aspect of pbx is that you can choose to receive CDR packages. Those packages have 2 timestamps : "utc" and "local", but both seem to always be the same.

Here's an example of a timestamp : "1268927156".

At first sight, there seems to be no logic in it. So I tried converting it several ways, but with no good result. That value should provide a time around 11am (+1GMT) today.

Things I tried:

  • Datetime dt = new Datetime(number);
  • Timespan ts = new Timespan(number);
  • DateTime utc = new DateTime(number + 504911232000000000, DateTimeKind.Utc)

and some others I can't remember right now.

Am I missing something stupid here?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

耶耶耶 2024-09-01 14:21:38

这看起来像 Unix 时间。

1268927156 = 2010 年 3 月 18 日星期四 15:45:56 GMT

代码示例:

DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
DateTime time = startDate.AddSeconds(1268927156 );

This looks like Unix time.

1268927156 = Thu, 18 Mar 2010 15:45:56 GMT

And a code sample:

DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
DateTime time = startDate.AddSeconds(1268927156 );
秋凉 2024-09-01 14:21:38

似乎是 Unix 时间戳(自纪元以来的秒数)

DateTime translated = new DateTime(1970,1,1).AddSeconds(1268927156);

应该为您提供您所在的日期和时间...

Seems to be a Unix timestamp (no. of seconds since the epoch)

DateTime translated = new DateTime(1970,1,1).AddSeconds(1268927156);

should give you the date and time you were after...

我不会写诗 2024-09-01 14:21:38

这看起来像一个unix时间戳,也就是no。自 1970 年 1 月 1 日以来的秒数。

DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(1268927156);

如果 utc 和本地时间戳相同,则 PBX 上的时区设置为 UTC,并且您的时间戳实际上是 UTC,或者时区设置为 UTC,但时间设置为您的本地时间,并且您将得到两个时间戳的本地时间。您必须弄清楚其中的哪一个,以便知道是否要从 UTC 转换时间戳。

That looks like a unix timestamp, which is the no. of seconds since Jan 01,1970.

DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(1268927156);

If both the utc and local timestamps are the same, the timezone on your PBX is either set to UTC, and your timestamps really are UTC, or the timezone is set to UTC but the time is set to your local time, and you get your local time for both of the timestamps. You'll have to figure out which of those so you'll know wether to convert the timestamps from UTC or not.

往事风中埋 2024-09-01 14:21:38

我猜这是一个 UNIX 时间戳,逻辑如下:

UNIX 时间戳表示自 Unix 纪元(1970 年 1 月 1 日 00:00:00 GMT)以来以秒为单位的时间

有一个 codeproject 文章 解释了转换。基本上你需要做的事情如下:

// First make a System.DateTime equivalent to the UNIX Epoch.
System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
// Add the number of seconds in UNIX timestamp to be converted.
dateTime = dateTime.AddSeconds(timestamp);

I guess this is a UNIX timestamp, the logic would be the following:

The UNIX timestamp represents the time measured in number of seconds since the Unix Epoch (1st of January 1970 00:00:00 GMT)

There is a codeproject article explaining the conversion. Basically what you need to do would be the following:

// First make a System.DateTime equivalent to the UNIX Epoch.
System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
// Add the number of seconds in UNIX timestamp to be converted.
dateTime = dateTime.AddSeconds(timestamp);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文