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

  • AginoEvolutionHD

    AginoEvoluti

    27 AĞUSTOS 2011
  • MVLV28

    MVLV28

    17 Mart 2008
  • ::..ηєѕѕ мιχ..::

    ::..ηєѕѕ

    15 Aralık 2006