레이블이 get current time인 게시물을 표시합니다. 모든 게시물 표시
레이블이 get current time인 게시물을 표시합니다. 모든 게시물 표시

2018년 3월 5일 월요일

python에서 현재시간으로 string만들기

<참조: https://stackoverflow.com/questions/3316882/how-do-i-get-a-string-format-of-the-current-date-time-in-python>

from datetime import datetime

def get_curtime_as_string():
    timestamp = '%d_%d_%d_%d_%d_%d_%d' % (
        datetime.now().year, 
        datetime.now().month, 
        datetime.now().day,
        datetime.now().hour,
        datetime.now().minute,
        datetime.now().second, 
        datetime.now().microsecond
    )
    
    return timestamp