使用JavaScript获取日期加随机数生成单号

今天学习Javascript,得到一个自动生成单号的JavaScript,留下日后备用:

 1        function getNowFormatDate() {
 2            var day = new Date();
 3            var Year = 0;
 4            var Month = 0;
 5            var Day = 0;
 6            var CurrentDate = "";
 7            Year = day.getFullYear(); //支持IE和火狐浏览器.
 8            Month = day.getMonth() + 1;
 9            Day = day.getDate();
10            CurrentDate += Year;
11            if (Month >= 10) {
12                CurrentDate += Month;
13            }
14            else {
15                CurrentDate += "0" + Month;
16            }
17            if (Day >= 10) {
18                CurrentDate += Day;
19            }
20            else {
21                CurrentDate += "0" + Day;
22            }
23            return CurrentDate;
24        }
25 
26        var OrderID = getNowFormatDate() + Math.floor(Math.random() * 1000);
27 
28        document.write("随机单号:" + OrderID + "<br />");

 

posted @ 2015-04-29 17:50  奔跑.Ken  阅读(1062)  评论(0编辑  收藏  举报