[PyQt] SIP API v2: datetime not being converted to QDateTime?

Jugdish jugdizh at gmail.com
Tue Apr 20 15:12:43 BST 2010


I'm trying to format Python datetime objects into strings using QLocale, but
it seems that under SIP API v2, the time information is lost? Are datetime
objects being interpreted as QDate rather than QDateTime? Here's an example:

#################
# API v1
#################
from PyQt4.QtCore import *
locale = QLocale()
locale.toString(QDateTime.currentDateTime(), locale.dateTimeFormat())
# returns PyQt4.QtCore.QString(u'Tuesday, 20 April 2010 15:06:19 ')

#################
# API v2
#################
import sip
sip.setapi("QString", 2)
sip.setapi("QDate", 2)
sip.setapi("QDateTime", 2)
sip.setapi("QTime", 2)
from PyQt4.QtCore import *
import datetime
locale = QLocale()
locale.toString(datetime.datetime.now(), locale.dateTimeFormat())
# returns u'Tuesday, 20 April 2010 HH:mm:ss '
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100420/2053e4f9/attachment.html>


More information about the PyQt mailing list