加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何以秒为单位创建时间戳

发布时间:2020-12-15 18:18:05 所属栏目:百科 来源:网络整理
导读:我有这个任务来填充这个字段: x_fp_timestamp is the timestamp created when the form is generated. It is equal to the number of seconds since January 1,1970 in UTC (Coordinated Universal Time). 所以我在C#中做的是 long ts = DateTime.Now.Ticks
我有这个任务来填充这个字段:

x_fp_timestamp is the timestamp created when the form is generated. It
is equal to the number of seconds since January 1,1970 in UTC
(Coordinated Universal Time).

所以我在C#中做的是

long ts =  DateTime.Now.Ticks / TimeSpan.TicksPerSecond;

但在这种情况下,我收到此错误:

  • x_fp_timestamp : x_fp_timestamp invalid. Not within 15 minutes of
    present time: Thu Jan 10 21:30:25 GMT 2013. Expected 1357853425
    plus/minus 900,but received 63493442997.

所以我的问题是如何在几秒钟内生成当前时间戳?

解决方法

DateTime.Now.Ticks does not start at 1970;尝试这样的事情:
(DateTime.Now.ToUniversalTime() - new DateTime (1970,1,1)).TotalSeconds

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读