惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
C
Cybersecurity and Infrastructure Security Agency CISA
N
News and Events Feed by Topic
C
Cisco Blogs
Cisco Talos Blog
Cisco Talos Blog
A
Arctic Wolf
Scott Helme
Scott Helme
P
Palo Alto Networks Blog
S
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tor Project blog
量子位
G
Google Developers Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog RSS Feed
NISL@THU
NISL@THU
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
AWS News Blog
AWS News Blog
爱范儿
爱范儿
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
L
LINUX DO - 最新话题
Security Archives - TechRepublic
Security Archives - TechRepublic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Secure Thoughts
Cloudbric
Cloudbric
aimingoo的专栏
aimingoo的专栏
L
Lohrmann on Cybersecurity
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hacker News: Ask HN
Hacker News: Ask HN
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
S
Security @ Cisco Blogs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cyber Attacks, Cyber Crime and Cyber Security
G
GRAHAM CLULEY
P
Proofpoint News Feed
V
V2EX
Martin Fowler
Martin Fowler
C
CERT Recently Published Vulnerability Notes
Attack and Defense Labs
Attack and Defense Labs
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Cloudflare Blog
SecWiki News
SecWiki News
罗磊的独立博客
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
小众软件
小众软件
The Last Watchdog
The Last Watchdog

博客园 - dcrenl

解决CapabilityAccessManager.db-wal 文件过大 Java 应用程序在linux环境中读取和写入 Microsoft Access 数据库(包括 .mdb 和 .accdb 格式)的开源库 windows 版本nginx报错:maximum number of descriptors supported by select() is 1024 while 删除多个网关 dot net6 在win7上运行报错 远程重启服务器 sqlserver 20008 R2 关闭TLS1.0无法启动服务的解决办法 rust 模块和引用 nohup java按天输出日志 idea 社区版本创建android原生项目 解决win11输入法自定义短语有多个当前日期只有最后一个生效 postgresql使用for循环 Win10打开IE自动跳转至Edge解决办法 身份认证与授权 pnpm : 无法加载文件 \AppData\Roaming\npm\pnpm.ps1,因为在此系统上禁止运行脚本。 - dcrenl win11 输入法自定义短语输出日期时间变量 SM系列国密算法 Opera打不开网页解决办法 excel 数字转中文大写金额 nginx http跳转到https
C# 获取时间戳
dcrenl · 2022-12-07 · via 博客园 - dcrenl

网上大多数都是使用两个时间相减获取时间戳,实际上获得的时间是有偏差的。

其实dot net默认就有获取时间戳的方法,在微软找到很久官方最终找到了这个方法地址在下方

https://learn.microsoft.com/zh-cn/dotnet/api/system.datetimeoffset?view=net-7.0

使用DateTimeOffset类可以获取时间戳,其中有两个方法


ToUnixTimeMilliseconds()
返回自 1970-01-01T00:00:00.000Z 起已经过的毫秒数。

ToUnixTimeSeconds()
返回自 1970-01-01T00:00:00.00Z 起已经过的秒数。

根据文档可以使用以下写法获取到秒的时间戳

new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();