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

前端之家收集整理的这篇文章主要介绍了c# – 如何以秒为单位创建时间戳前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个任务来填充这个字段:

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
原文链接:https://www.f2er.com/csharp/98100.html

猜你在找的C#相关文章