- <html><head>
- <title>根据时间生成uuid</title>
- <script>
- Date.prototype.Format = function (fmt) { //author: marver
- var o = {
- "M+": this.getMonth() + 1, //月份
- "d+": this.getDate(), //日
- "h+": this.getHours(), //小时
- "m+": this.getMinutes(), //分
- "s+": this.getSeconds(), //秒
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
- "S": this.getMilliseconds() //毫秒
- };
- if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (var k in o)
- if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
- return fmt;
- }
- function oddNumber(num) {
- var taskTime = new Date().Format("yyyyMMddhhmmss");;
- //将数据库中最大的一条记录取出来,假如是:HL20150921105230001
- //String yd ="HL20150921105230001";
- if(num==""||num==null){
- num="HL20150921105230001";
- }
- var lastNumber=num.substring(num.length-3);
- var newNumber=(parseInt(lastNumber)+1);
- if(newNumber.toString().length==1){
- newNumber="00"+newNumber;
- }
- if(newNumber.toString().length==2){
- newNumber="0"+newNumber;
- }
- var temp="HL"+taskTime+newNumber;
- return temp;
- }
- function CGUI()
- {
- var uuid=document.getElementById("GUIDshow").innerHTML;
- document.getElementById("GUIDshow").innerHTML= oddNumber(uuid);
- }
- </script>
- </head>
- <body>
- <p id="GUIDshow"></p>
- <input type="button" id="uids" value="生成唯一的uuid值" onclick="CGUI()">
- </body>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/0810201513746.html
来源: http://www.codesnippet.cn/detail/0810201513746.html