A library that computes the ephemerides.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

15 行
384 B

  1. #!/usr/bin/env python3
  2. from datetime import datetime, timezone, timedelta
  3. def translate_to_timezone(date: datetime, to_tz: int, from_tz: int = None):
  4. if from_tz is not None:
  5. source_tz = timezone(timedelta(hours=from_tz))
  6. else:
  7. source_tz = timezone.utc
  8. return date.replace(tzinfo=source_tz).astimezone(
  9. tz=timezone(timedelta(hours=to_tz))
  10. )