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

标签 c# .net timestamp seconds

我有这个任务来填充这个字段:

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

关于c# - 如何以秒为单位创建时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14267984/

相关文章:

c# - 要比较 double 和十进制,我应该将 double 转换为十进制还是将十进制转换为 double ?

c# - LINQ .ToListAsync 在使用两个表时失败

c# - xaml 中使用的通用类型的 TypeConverter

.net - 验证密码的最小/最大长度

.net - 如何在 Ubuntu 16.04 LTS 上安装 dotnet SDK

c# - 如何根据 C# 中的枚举值获得优势?

python - 在 pandas 中分割时间戳日期

node.js - 在 Node.js 中访问 HTTP 请求的时间戳

java - Vlcj - 如何使用 Java 获取时间戳?

c# - 如何更新 ObservableCollection 类中的单个项目?