欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

用JS實(shí)現(xiàn)根據(jù)當(dāng)前時(shí)間隨機(jī)生成流水號(hào)或者訂單號(hào)

 更新時(shí)間:2018年05月31日 08:53:03   作者:愛吃漁的熊  
本文通過實(shí)例代碼給大家介紹了基于JS實(shí)現(xiàn)根據(jù)當(dāng)前時(shí)間隨機(jī)生成流水號(hào)或者訂單號(hào)的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

既然是根據(jù)當(dāng)前的時(shí)間,那么我們第一步就是獲取當(dāng)前時(shí)間,然后拼接一個(gè)隨機(jī)數(shù),這樣便實(shí)現(xiàn)了隨機(jī)生成一個(gè)流水號(hào),注意由于要求每個(gè)流水號(hào)都是獨(dú)一無二的,生成后提交的過程中還是需要驗(yàn)證當(dāng)前的流水號(hào)是否存在,如果存在則需要提示用戶或者再次生成。

//   根據(jù)當(dāng)前時(shí)間和隨機(jī)數(shù)生成流水號(hào)
   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 = this.setTimeDateFmt(month)
    hour = this.setTimeDateFmt(hour)
    minutes = this.setTimeDateFmt(minutes)
    seconds = this.setTimeDateFmt(seconds)
    return now.getFullYear().toString() + month.toString() + day + hour + minutes + seconds + (Math.round(Math.random() * 89 + 100)).toString()
   }

總結(jié)

以上所述是小編給大家介紹的用JS實(shí)現(xiàn)根據(jù)當(dāng)前時(shí)間隨機(jī)生成流水號(hào)或者訂單號(hào),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論