DateTime的表示形式为毫秒? [英] DateTime's representation in milliseconds?

查看:144
本文介绍了DateTime的表示形式为毫秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQL Server服务器时间戳,我需要转换为自1970年以来以毫秒为单位的时间表示。我可以用简单的SQL来做到吗?如果没有,我将其解压缩到C#中的 DateTime 变量。谢谢,

Teja。

解决方案

你可能正在尝试转换为类似UNIX的时间戳,它们是UTC:

  yourDateTime.ToUniversalTime()。Subtract(
new DateTime(1970,1,1,0,0,DateTimeKind.Utc)
).TotalMilliseconds

这也避免了夏季问题,因为UTC没有那些。


I have a SQL-server timestamp that I need to convert into a representation of time in milliseconds since 1970. Can I do this with plain SQL? If not, I've extracted it into a DateTime variable in C#. Is it possible to get a millisec representation of this ?

Thanks,
Teja.

解决方案

You're probably trying to convert to a UNIX-like timestamp, which are in UTC:

yourDateTime.ToUniversalTime().Subtract(
    new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
    ).TotalMilliseconds

This also avoids summertime issues, since UTC doesn't have those.

这篇关于DateTime的表示形式为毫秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆