将本地时间(10 位数字)转换为可读的日期时间格式
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这看起来像 Unix 时间。
1268927156 = 2010 年 3 月 18 日星期四 15:45:56 GMT
代码示例:
This looks like Unix time.
1268927156 = Thu, 18 Mar 2010 15:45:56 GMT
And a code sample:
似乎是 Unix 时间戳(自纪元以来的秒数)
应该为您提供您所在的日期和时间...
Seems to be a Unix timestamp (no. of seconds since the epoch)
should give you the date and time you were after...
这看起来像一个unix时间戳,也就是no。自 1970 年 1 月 1 日以来的秒数。
如果 utc 和本地时间戳相同,则 PBX 上的时区设置为 UTC,并且您的时间戳实际上是 UTC,或者时区设置为 UTC,但时间设置为您的本地时间,并且您将得到两个时间戳的本地时间。您必须弄清楚其中的哪一个,以便知道是否要从 UTC 转换时间戳。
That looks like a unix timestamp, which is the no. of seconds since Jan 01,1970.
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.
我猜这是一个 UNIX 时间戳,逻辑如下:
有一个 codeproject 文章 解释了转换。基本上你需要做的事情如下:
I guess this is a UNIX timestamp, the logic would be the following:
There is a codeproject article explaining the conversion. Basically what you need to do would be the following: