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

  • Andrea Lewis

    Andrea Lewis

    14 Mart 2013
  • Cole Rolland

    Cole Rolland

    23 Kasım 2008
  • Kindness

    Kindness

    23 Ocak 2006