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

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
SegmentFault 最新的问题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Attack and Defense Labs
Attack and Defense Labs
F
Full Disclosure
Vercel News
Vercel News
N
News | PayPal Newsroom
The GitHub Blog
The GitHub Blog
H
Hacker News: Front Page
H
Heimdal Security Blog
P
Privacy International News Feed
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cisco Blogs
L
Lohrmann on Cybersecurity
D
Docker
Recent Announcements
Recent Announcements
Security Archives - TechRepublic
Security Archives - TechRepublic
人人都是产品经理
人人都是产品经理
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Check Point Blog
博客园 - 叶小钗
Google Online Security Blog
Google Online Security Blog
Martin Fowler
Martin Fowler
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
S
Secure Thoughts
博客园 - Franky
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
P
Palo Alto Networks Blog
Latest news
Latest news
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
The Cloudflare Blog
Last Week in AI
Last Week in AI
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cyberwarzone
Cyberwarzone
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
Hacker News: Ask HN
Hacker News: Ask HN
T
Threatpost
T
Tenable Blog
P
Privacy & Cybersecurity Law Blog
WordPress大学
WordPress大学

博客园 - yellowyu

驴家网www.lvjia.cn全站全静态,其实技术在于活学活用 5年程序员流水帐总结,从开发到产品过渡 过滤HTML标签的几个函数 解决WCF传输大数据量时出错 使用InternetSetCookie 从System.Environment.TickCount 看最大支持,机子开一开还是要重启一下的 转:关系数据库中关系模式的规范过程 个人宣传画 我的身体已不再属于我 每一条路都是坚辛的,从未有平坦的 程序员与白咖啡,一种心情 真实故事:我的女友 今天做了淘宝客了。。。呵呵 暂时离开!=不再CODE Remoting: 如何穿越防火墙 (转) .NET 中的对象序列化(转) Remoting :关于广域网事件回调失败与值传递 Winform:关于IM好友列表 Remoting(转)
JScript 中Date.getTime转.Net中的DateTime
yellowyu · 2010-08-24 · via 博客园 - yellowyu

JS中的getTime与.Net中的DateTime.Ticks意义相近,所以相互转换时,需要用到这两个概念;但是getTime与 Ticks的意义有所区别,请看以下定义:

JS中getTime的定义:
getTime() 方法可返回距 1970 年 1 月 1 日之间的毫秒数。

C#中的Ticks
此属性的值表示自 0001 年 1 月 1 日午夜 12:00:00以来经过的以 100 纳秒为间隔的间隔数。

对几个词来说明一下,纳秒也叫毫微秒,相互之前的转换关系是 :

1秒   = 10^3 毫秒
1毫秒 = 10^3 微秒
1微秒 = 10^3 毫微秒

查看getTime与Ticks的定义后,可 以得知getTime以毫秒为单位,Ticks以100纳秒为单位,因此getTime与 Ticks相差了 1000 * 1000 / 100;getTime()从1970-1-1开始计算,而Ticks从0001-1-1开始计算,因此Ticks多了1970-1-1之前的时间;转换 公式如下:

getTime() * 1000 * 1000 / 100 + DateTime.Parse("1970-1-1").Ticks

测试程序如下:

//JS时间转.net时间
long jsGetTime = 1247617999000;
Console.WriteLine(jsGetTime);
long jsBeginTick = DateTime.Parse("1970-1-1").Ticks;

long netTicks = jsGetTime * 1000 * 10 + jsBeginTick;
DateTime dt = new DateTime(netTicks);
Console.WriteLine(dt.ToString("yyyy-MM-dd HH:mm:ss"));
DateTime dt2 = dt.ToLocalTime();
Console.WriteLine(dt2.ToString("yyyy-MM-dd HH:mm:ss"));

//.Net时间转JS getTime();
long dt2Ticks = dt2.ToUniversalTime().Ticks;
long dt2JsTicks = (dt2Ticks - jsBeginTick) / (1000 * 10);
Console.WriteLine(dt2JsTicks);
Console.Read();

来 自:

http://www.cnblogs.com/jordan2009/archive/2009/08/17/1547875.html 

        private long GetJsTimes()
        {
            DateTime dt = DateTime.Now;
            long dtTicks = dt.ToUniversalTime().Ticks;
            long jsBeginTick = DateTime.Parse("1970-1-1").Ticks;
            long dtJsTicks = (dtTicks - jsBeginTick) / (1000 * 10);
            return dtJsTicks;
        }

        private DateTime ToDotnetTime(long jsTime)
        {
            long jsBeginTick = DateTime.Parse("1970-1-1").Ticks;

            long netTicks = jsTime * 1000 * 10 + jsBeginTick;
            DateTime dt = new DateTime(netTicks);
            DateTime dt2 = dt.ToLocalTime();

            return dt2;

        }