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

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - 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;

        }