[python] time, date, datetime
timeout
time
```python
time.time() #UTC 기준 초단위 실수형 리턴
time.localtime() #초단위 실수형 리턴값을 연,월,시 등의 time.struct_time(투플)로 리턴
time.asctime() #time.struct_time을 보기 좋은 형태로 리턴
time.ctime() == time.asctime(time.localtime(time.time()))
time.strftime('형식 포맷 코드', time.localtime(time.time()))
time.sleep()
```
date
```python
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2017, 11, 12, 8, 12, 50, 236423)
>>> datetime.datetime.now().strftime('%y%m%d-%H%M')
'171112'
>>> (datetime.now() - timedelta(minutes=20)).isoformat(timespec='seconds')
'2018-07-25T00:32:17'
>>> datetime.date.today()
datetime.date(2017, 11, 12)
>>> datetime.date.today().strftime('%y%m%d')
'171112'
>>> str_date = '2004/03/30'
>>> date = datetime.strptime(str_date, "%Y/%m/%d")
```
```py
def get_utc():
hours = int(time.localtime().tm_gmtoff / 3600)
minutes = time.localtime().tm_gmtoff % 60
return "+{0:0>2}:{1:0>2}".format(hours, minutes)
```
https://github.com/umbum/Python-snippet/blob/master/extract_days_by_month.py
'Languages & Frameworks > Python' 카테고리의 다른 글
[python] docstring, 문서화 (0) | 2018.10.15 |
---|---|
[python] @property, getter setter, private 필드 (0) | 2018.08.07 |
[python] File IO open 함수 및 내장함수 (0) | 2017.09.22 |
[python] pyplot.matplotlib (0) | 2017.09.13 |
[python] asyncio (8) | 2017.08.27 |