且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用系统时间生成唯一ID?

更新时间:2023-08-19 18:19:16

如何使用Guid类来生成一个新的Guid?


" Nina" <镍** @ discussions.microsoft.com>在消息中写道

news:36 ********************************** @ microsof t.com ...
What about using the Guid class to generate a new Guid?

"Nina" <Ni**@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
我需要为我的应用程序生成唯一的id。使用系统时间创建
id,这是最合适的,但我不知道该怎么做。请帮忙。

提前感谢您的任何意见。
I need to generate unique id for my application. Use system time to create
id, which is the best fit, but I don''t know how to do it. Please help.

Thanks in advance for any input.



GUID是获得独特感的好方法id但是如果你想让你的id与时间有一些

的关系,为什么不尝试使用自创建文件以来的天数,分钟数或
秒最后更新?实际上,我相信应用程序productBuildPart信息可以为您提供自2000年1月1日至文件修改的最后一天的数字天数?b / b />
System.Diagnostics.FileVersionInfo.GetVersionInfo(_

System.Reflection.Assembly.GetExecutingAssembly.Lo cation).ProductBuildPart


如果你想要时间,在这种情况下使用分钟,在文件创建时间到文件上次修改时间之间尝试 -


System.IO.File .GetLastWriteTime(_

System.Reflection.Assembly.GetExecutingAssembly.Lo cation).Subtract(_

System.IO.File.GetCreationTime(_
$ b) $ b System.Reflection.Assembly.GetExecutingAssembly.Lo cation))。TotalMinutes


Dave


" Nina" &LT;镍** @ discussions.microsoft.com&GT;在消息中写道

news:36 ********************************** @ microsof t.com ...
GUID is a good way to get a unique id but if you want your id to have some
relationship to the time why not try using the number of days, minutes, or
seconds since the file was created until it was last updated? Actually, I
beleive the applications productBuildPart information gives you the number
of days since January 1, 2000 to the last day the file was modified?

System.Diagnostics.FileVersionInfo.GetVersionInfo( _
System.Reflection.Assembly.GetExecutingAssembly.Lo cation).ProductBuildPart

If you want the time, in this case using minutes, between when the file was
created to when the file was last modified try -

System.IO.File.GetLastWriteTime( _
System.Reflection.Assembly.GetExecutingAssembly.Lo cation).Subtract( _
System.IO.File.GetCreationTime( _
System.Reflection.Assembly.GetExecutingAssembly.Lo cation)).TotalMinutes

Dave

"Nina" <Ni**@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
我需要为我的应用程序生成唯一的id。使用系统时间创建
id,这是最合适的,但我不知道该怎么做。请帮忙。

提前感谢您的任何意见。
I need to generate unique id for my application. Use system time to create
id, which is the best fit, but I don''t know how to do it. Please help.

Thanks in advance for any input.



" Nina" &LT;镍** @ discussions.microsoft.com&GT; schrieb:
"Nina" <Ni**@discussions.microsoft.com> schrieb:
我需要为我的应用程序生成唯一的id。使用系统时间创建
id,这是最合适的,但我不知道该怎么做。
I need to generate unique id for my application. Use system time to create
id, which is the best fit, but I don''t know how to do it.




最简单的解决方案是使用一个GUID:


\\\

Dim ID As String = Guid.NewGuid()。ToString()

///


-

MS Herfried K. Wagner

MVP< URL:http:// dotnet。 mvps.org/>

VB< URL:http://dotnet.mvps.org/dotnet/faqs/>



The simplest solution is using a GUID:

\\\
Dim ID As String = Guid.NewGuid().ToString()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>