doxgxxn / WILT

0 stars 0 forks source link

231004 / datetime, timetuple, time #60

Open doxgxxn opened 1 year ago

doxgxxn commented 1 year ago
import pytz
from datetime import datetime

tz = pytz.timezone('Asia/Seoul')
tz
### 출력 <DstTzInfo 'Asia/Seoul' LMT+8:28:00 STD>

datetime.now()
### datetime.datetime(2023, 10, 4, 12, 45, 26, 562110)

str(datetime.now())[:16]
### 출력 '2023-10-04 12:44'

datetime.strptime(str(datetime.now())[:16], '%Y-%m-%d %H:%S')
### 출력 datetime.datetime(2023, 10, 4, 12, 0, 44)

datetime.strptime(str(datetime.now())[:16], '%Y-%m-%d %H:%S').timetuple()
### 출력 time.struct_time(tm_year=2023, tm_mon=10, tm_mday=4, tm_hour=12, tm_min=0, tm_sec=43, tm_wday=2, tm_yday=277, tm_isdst=-1)

nowtime = time.mktime(datetime.strptime(str(datetime.now())[:16], '%Y-%m-%d %H:%S').timetuple())
nowtime
### 출력 1696388446.0

datetime.fromtimestamp(nowtime, tz=tz)
### 출력 datetime.datetime(2023, 10, 4, 12, 0, 46, tzinfo=<DstTzInfo 'Asia/Seoul' KST+9:00:00 STD>)