Created
May 18, 2014 06:43
-
-
Save jamiesun/d25d4680cdd79482fe60 to your computer and use it in GitHub Desktop.
生成有时间规则的id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
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()