SORU
10 EYLÜL 2010, Cuma


Python dönüştürme unix zaman damgası tarih okunabilir dize

Bir dize bir unix zaman damgası temsil eden ("1284101485") Python ve okunabilir bir tarih dönüştürmek istiyorum. yani time.strftime. TypeError.

>>>import time
>>>print time.strftime("%B %d %Y", "1284101485")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument must be 9-item sequence, not str

CEVAP
10 EYLÜL 2010, Cuma


Kullanım datetime modül:

import datetime
print(
    datetime.datetime.fromtimestamp(
        int("1284101485")
    ).strftime('%Y-%m-%d %H:%M:%S')
)

Bu kod datetime.datetime garip görünebilir, ama 1 datetime modül ismi ve 2. sınıf adıdır. datetime.datetime.fromtimestamp() datetime modülü datetime sınıf 10 ** yöntemdir.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Autocar

    Autocar

    11 Mart 2006
  • Jeremy Gallman

    Jeremy Gallm

    11 NİSAN 2012
  • mipd1980

    mipd1980

    25 EKİM 2006