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

  • Flohoo

    Flohoo

    12 EYLÜL 2009
  • kimaliz

    kimaliz

    18 Temmuz 2006
  • Kyletiv7

    Kyletiv7

    28 Mayıs 2007