本文介绍了如何在Javascript或jquery中将C#DateTime.Ticks转换为javascript日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嘿那里, 所以我得到以下值(实际上是C#DateTime.Ticks)635556672000000000到javascript中的Date对象? 我一直在谷歌搜索相当多,但无法找到帮助我的答案。 所以我在这里试试运气: ) 谢谢!Hey there, so I am getting the following value ( which is indeed C# DateTime.Ticks ) 635556672000000000 to a Date object in javascript?I've been googling for quite a bit but wasn't able to find an answer that helps me.So I am trying my luck here :)Thank you!推荐答案 DateTime someDate = new DateTime(635556672000000000); // or whatever variable has your ticksInt32 unixTimestamp = (Int32)(someDate.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;unixTimestamp = unixTimestamp * 1000; 一旦你'设置了一些内容,以便您可以从ASP.NET资源中获取unixTimestamp的值,只需通过jQuery等调用它。例如,假设您创建一个名为time.ashx的ASP.NET Web处理程序,它将缩略图标记作为明文吐出: Once you've set something up so that you can get the value of unixTimestamp out of an ASP.NET resource, just call it via jQuery or the like. For example, supposing you create an ASP.NET web handler, named time.ashx, that spits out the microtime stamp as plaintext:var myTimestamp = new Date(); //set default date to now 或类似的东西。要点是:ASP.NET助手将ticks转换为microtime。Or something similar. Point is: ASP.NET helper to convert ticks to microtime. var ticks = 635556672000000000; //ticks are in nanotime; convert to microtimevar ticksToMicrotime = ticks / 10000;//ticks are recorded from 1/1/1; get microtime difference from 1/1/1/ to 1/1/1970var epochMicrotimeDiff = 2208988800000;//new date is ticks, converted to microtime, minus difference from epoch microtimevar tickDate = new Date(ticksToMicrotime - epochMicrotimeDiff); tickDate现在是您的滴答时间戳反映的日期。 http:/ /msdn.microsoft.com/en-us/library/system.datetime.ticks%28v=vs.110%29.aspx [ ^ ] 另外,protip:尝试更愉快,你会发现人们更愿意帮助你。我是一个人,没有计划再次帮助你。 tickDate is now the date reflected by your ticks timestamp.http://msdn.microsoft.com/en-us/library/system.datetime.ticks%28v=vs.110%29.aspx[^]Also, protip: Try to be more pleasant, you'll find people are more willing to help you. I, for one, have no plans to assist you again. 这篇关于如何在Javascript或jquery中将C#DateTime.Ticks转换为javascript日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-20 17:46