知識
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價值,我們在追求其視覺表現(xiàn)的同時,更側(cè)重于功能的便捷,營銷的便利,運營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!
您當前位置>首頁 » 新聞資訊 » 小程序相關(guān) >
微信小程序 - 隨機生成訂單號(JavaScript)
發(fā)表時間:2020-10-1
發(fā)布人:葵宇科技
瀏覽次數(shù):209
前言
如題,隨機生成訂單號是很常見的需求,如下圖所示:
第一種
可自己拼接其他字母。
時間戳 + 6位隨機數(shù)的訂單號。
function orderCode()
{
// 存放訂單號
let orderCode = '';
// 6位隨機數(shù)(加在時間戳后面)
for (var i = 0; i < 6; i++)
{
orderCode += Math.floor(Math.random() * 10);
}
// 時間戳(用來生成訂單號)
orderCode = 'D' + new Date().getTime() + orderCode;
// 打印
console.log(orderCode)// D1601545805958923658
}
第二種
日期 + 6位隨機數(shù)的訂單號。
function setTimeDateFmt(s) { // 個位數(shù)補齊十位數(shù)
return s < 10 ? '0' + s : s;
}
function randomNumber() {
const now = new Date()
let month = now.getMonth() + 1
let day = now.getDate()
let hour = now.getHours()
let minutes = now.getMinutes()
let seconds = now.getSeconds()
month = setTimeDateFmt(month)
day = setTimeDateFmt(day)
hour = setTimeDateFmt(hour)
minutes = setTimeDateFmt(minutes)
seconds = setTimeDateFmt(seconds)
let orderCode = now.getFullYear().toString() + month.toString() + day + hour + minutes + seconds + (Math.round(Math.random() * 1000000)).toString();
console.log(orderCode)
return orderCode;
}
結(jié)果:
20190909103109582536
相關(guān)案例查看更多
相關(guān)閱讀
- 網(wǎng)絡(luò)公司報價
- 前端開發(fā)
- 云南網(wǎng)站建設(shè)專家
- 網(wǎng)站建設(shè)哪家強
- 二叉樹
- .net網(wǎng)站
- 網(wǎng)站建設(shè)選
- 云南網(wǎng)站建設(shè)方法
- 做網(wǎng)站
- 云南網(wǎng)站建設(shè)公司
- 云南網(wǎng)站建設(shè)首選公司
- 小程序的開發(fā)公司
- 網(wǎng)絡(luò)公司聯(lián)系方式
- 楚雄網(wǎng)站建設(shè)公司
- 開發(fā)框架
- 網(wǎng)站建設(shè)百度官方
- 百度推廣
- 搜索引擎自然排名
- 云南省建設(shè)廳官方網(wǎng)站
- 小程序生成海報
- 智慧農(nóng)貿(mào)市場
- 報廢車回收管理軟件
- 云南網(wǎng)站制作哪家好
- 云南小程序開發(fā)推薦
- 汽車拆解系統(tǒng)
- 云南小程序開發(fā)
- 國內(nèi)知名網(wǎng)站建設(shè)公司排名
- 報廢車拆解回收管理系統(tǒng)
- 網(wǎng)站建設(shè)優(yōu)化
- 云南小程序設(shè)計