Skip to content

Instantly share code, notes, and snippets.

@jamiesun
Created May 18, 2014 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jamiesun/d25d4680cdd79482fe60 to your computer and use it in GitHub Desktop.
Save jamiesun/d25d4680cdd79482fe60 to your computer and use it in GitHub Desktop.
生成有时间规则的id
import datetime
def __next_id():
_inum = [10000]
def _next():
if _inum[0] >= 99999:
_inum[0] = 10000
_inum[0] += 1
_prefix = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
return int("%s%s"%(_prefix,_inum[0]))
return _next
nextid = __next_id()
if __name__ == '__main__':
print nextid()
@ysling
Copy link

ysling commented Aug 27, 2017

import datetime

def __next_id():
_inum = [10000]
def _next():
if _inum[0] >= 99999:
_inum[0] = 10000
_inum[0] += 1
_prefix = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
return int("%s%s"%(_prefix,_inum[0]))
return _next

nextid = __next_id()

if name == 'main':
print nextid()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment