首页 > 解决方案 > Python (PyPy) times.to_universal() 在 Alpine linux 上不起作用

问题描述

timezone我在 Alpine linux 容器中使用时间转换器时遇到问题,无论我指定什么,它都会导致相同的时间。与我的本地主机 Ubuntu 相比,结果是具有相同times版本的不同事件。

times==0.7在两个系统上

在 Alpine Docker 容器上,我tzdata在 CET 和 localhost 上安装并正确设置了时区。它显示命令的相同日期/时间date

alpine-pypy:3.6-7-alpine3.9 容器,root 用户

Python 3.6.1 (de061d87e39c7df4e436974096d7982c676a859d, Mar 25 2019, 18:43:49)
[PyPy 7.1.0-beta0 with GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``I might, but nobody respects me''
>>>> import times
>>>> from datetime import datetime
>>>> times.to_universal(datetime(2017, 12, 24, 13, 50, 24, 124), 'CET')
datetime.datetime(2017, 12, 24, 13, 50, 24, 124)
>>>> times.to_universal(datetime(2017, 12, 24, 13, 50, 24, 124), 'Japan')
datetime.datetime(2017, 12, 24, 13, 50, 24, 124)
>>>> times.to_universal(datetime(2017, 12, 24, 13, 50, 24, 124))
    datetime.datetime(2017, 12, 24, 13, 50, 24, 124)

在本地主机 Ubuntu 20.04 上,pypy3

Python 3.6.9 (7.3.2+dfsg-2~ppa1~ubuntu20.04, Sep 26 2020, 22:37:47)
[PyPy 7.3.2 with GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>> import times;from datetime import datetime
>>>> times.to_universal(datetime(2017, 12, 24, 13, 50, 24, 124), 'CET')
datetime.datetime(2017, 12, 24, 12, 50, 24, 124)
>>>> times.to_universal(datetime(2017, 12, 24, 13, 50, 24, 124), 'Japan')
datetime.datetime(2017, 12, 24, 4, 50, 24, 124)
>>>> times.to_universal(datetime(2017, 12, 24, 13, 50, 24, 124))
datetime.datetime(2017, 12, 24, 13, 50, 24, 124)

Dockerfile 重现

FROM jamiehewland/alpine-pypy:3.6-7-alpine3.9
#FROM python:3.7.9-alpine3.11

ENV TZ CET

RUN apk update && apk upgrade \
    && apk add bash libxml2-dev libxslt-dev build-base tzdata \
    && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
    && echo $TZ > /etc/timezone

RUN pip install --upgrade pip setuptools

RUN pip install times==0.7

请问有什么建议吗?

标签: pythontimealpinepypy

解决方案


推荐阅读