Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

javascript - 刻度转换在C#和Javascript中有所不同(Ticks Conversion Differs in C# and Javascript)

I want to generate unique number for some value.(我想为某些值生成唯一编号。)

So I tried to do it ticks conversion.(所以我试图做到刻度转换。) Earlier I generating unique number from server side that is from c#.(早些时候,我从服务器端从c#生成唯一编号。) So I used the following line of code for generate(所以我使用以下代码行生成) ConfirmationNumber = DateTime.Now.Ticks; It returns 18 digit integer value.(它返回18位整数值。) To cross check I checked the tick value in the https://tickstodatetime.azurewebsites.net/ .(为了进行交叉检查,我检查了https://tickstodatetime.azurewebsites.net/中的刻度值。) It gives the exact DateTime.(它给出了确切的DateTime。) Now, For some business perspective I want to generate the same unique number from UI (javascript).(现在,从某种角度来看,我想从UI(javascript)生成相同的唯一编号。) So I tried like below(所以我尝试如下) ConfirmationNumber = new Date().getTime(); It returns 13 digit integer value.(它返回13位整数值。) Again I checked with the tick conversion website.(再次,我检查了刻度线转换网站。) It returns wrong DateTime.(它返回错误的DateTime。) So How to get the same value which C# provides for DateTime.Now.Ticks in javascript?(那么,如何获得C#为javascript中的DateTime.Now.Ticks提供的值?)   ask by rajesh translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're trying to compare two entirely different things.(您正在尝试比较两个完全不同的事物。)

DateTime.Now.Ticks :(DateTime.Now.Ticks :) A single tick represents one hundred nanoseconds or one ten-millionth of a second.(一个滴答声代表一百纳秒或一百万分之一秒。) There are 10,000 ticks in a millisecond, or 10 million ticks in a second.(毫秒内有10,000个滴答声,在一秒内有1,000万个滴答声。) The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 (0:00:00 UTC on January 1, 0001, in the Gregorian calendar), which represents DateTime.MinValue.(此属性的值表示自0001年1月1日午夜12:00:00(公历0001年1月1日0:00:00 UTC)以来经过的100纳秒间隔数,它表示DateTime .MinValue。) It does not include the number of ticks that are attributable to leap seconds.(它不包括归因于leap秒的刻度数。) new Date().getTime() :(new Date().getTime() :) The getTime() method returns the number of milliseconds* since the Unix Epoch [January 01, 1970](getTime()方法返回自Unix纪元[1970年1月1日]以来的毫秒数*。) So you're comparing the number of milliseconds since Jan 1 0001 multiplied by 10,000 to the number of milliseconds since 1 Jan 1970. Of course they're going to be different.(因此,您正在将自0001年1月1日以来的毫秒数乘以10,000与自1970年1月1日以来的毫秒数进行比较。当然,它们将有所不同。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...