admin管理员组文章数量:1318977
I'm using the following 2 lines of JS to create a UID:
var UID = dateobj.getTime();
UID = String(UID).substr(4);
It appears that sometimes it generates a number like:
564929300
other times like:
56492930
Problem is the length isn't consistent which is messing things up. Any ideas how that's possible and if there is a way to fix this or a better way to make a UID with JS?
Thanks
I'm using the following 2 lines of JS to create a UID:
var UID = dateobj.getTime();
UID = String(UID).substr(4);
It appears that sometimes it generates a number like:
564929300
other times like:
56492930
Problem is the length isn't consistent which is messing things up. Any ideas how that's possible and if there is a way to fix this or a better way to make a UID with JS?
Thanks
Share Improve this question edited Jul 13, 2010 at 23:27 Yacoby 55.5k16 gold badges117 silver badges121 bronze badges asked Jul 13, 2010 at 23:26 AnApprenticeAnApprentice 111k202 gold badges637 silver badges1k bronze badges 1- what date range are you dealing with? – meder omuraliev Commented Jul 13, 2010 at 23:30
2 Answers
Reset to default 8I like doing Math.random().toString(36).substr(2,9)
There one implementation here: http://blog.shkedy./2007/01/createing-guids-with-client-side.html
Here it is in action: http://jsfiddle/7sXL6/
I threw together a smaller version of it: http://jsfiddle/7sXL6/4/
本文标签: uuidJAVASCRIPTdateobjgetTime for a UIDIs the length not fixedStack Overflow
版权声明:本文标题:uuid - JAVASCRIPT - dateobj.getTime for a UID - Is the length not fixed? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742056877a2418349.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论