jsup 2.1 - investor's relief (experiment on separation of investment and SNS)

by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/jsup-2-1-investor-s-relief-experiment-on-separation-of-investment-and-sns Hello, this is @joviansummer(witness: @jswit). I'm starting a new experiment regarding my @jsup vote service. The purpose of this experiment is to separate STEEM investment and social interaction(posting/commenting). For many people, writing a post daily(literally 365 posts per year) is not easy. It's not fun, and mandatory daily post only written for self-voting delegation service tends to result in useless low-quality content. I hope this new function of @jsup will reduce those posts, and also make it a bit more easy to invest in STEEM without worrying about daily posting. I think pressure of daily posting significantly undermines Steem as SNS. It's not fun. This is how it works: From 11:45 PM to 11:50 PM every night(reference time zone is GMT+9), @jsup checks if eligible delegators wrote something and received daily v...

파이썬에서 시간대(timezone) 변경

by joviansummer
original STEEMIT post: https://steemit.com/blog/@joviansummer/timezone


파이썬에서 시간대(timezone)를 변경하는 방법을 간단하게 메모해 둡니다.

datetime 모듈과 dateutil 모듈을 사용해서 현재 시간을 다른 시간대로 변환해서 출력할 수 있습니다.

from datetime import datetime
import pytz

# 현재 시각을 UTC/GMT 기준으로 now에 할당
now = datetime.utcnow()

# 현재 시각을 지역 시간대 기준으로 now_local에 할당
now_local = datetime.now()

datetime 객체인 now에 저장된 시간 정보를 원하는 형식에 맞춰서 문자열로 출력하기 위해 strftime() 함수를 이용합니다.

# 현재 시각 출력 (UTC/GMT)
now.strftime("%Y-%m-%d %H:%M:%S")

'2021-04-10 13:48:54'

# 현재 시각 출력 (KST)
now_local.strftime("%Y-%m-%d %H:%M:%S")

'2021-04-10 22:48:54'

위의 값은 UTC/GMT 기준이므로, 이것을 한국 시간대로 바꿉니다. 우선 시간대 정보(tzinfo)를 가져와 변수 UTC, KST에 할당합니다.

# 한국 시간대 정보를 KST에 할당
UTC = pytz.timezone('UTC')
KST = pytz.timezone('Asia/Seoul')

now에 할당된 datetime 객체에 시간대가 GMT/UTC라는 정보를 추가합니다.

# now의 시간대 정보를 UTC로 설정하여 now_utc에 할당
now_utc = now.replace(tzinfo=UTC)

now_utc의 시간대가 GMT/UTC라고 명시되었으므로, 이 시간 정보를 다른 시간대 기준으로 환산할 수 있습니다.

# now_utc의 시간대를 한국 시간대로 변환하여 now_kst에 할당
now_kst=now_utc.astimezone(KST)

시간대 정보를 한국 시간대로 변경한 now_kst의 시간 정보를 출력해 봅니다.

now_kst.strftime("%Y-%m-%d %H:%M:%S") '2021-04-10 22:48:54'

Comments

Popular posts from this blog

스티미언의 영향력 지수 계산

jsup/avle code update - you don't have to write post everyday

jsup/avle 보팅 코드 갱신 - 1일1포스팅 강박에서 벗어나기