qdatetime

QDateTimeEdit: rollback from 59 to 00 or vice-versa in hours/minute/second

浪尽此生 提交于 2019-12-22 13:53:00
问题 How can I rollback hour/min/sec from 59 to 00 or vice versa. Actually QDateTimeEdit doesn't allow it by default and it get stuck after reaching maximum value of 59 if tried pressing up arrow, and same for minimum value 00 . 回答1: You must know that QDateTimeEdit is inherit QAbstractSpinBox , and QAbstractSpinBox has wrapping mechanism, using it you can make your spins circular. So, all what you must do is setWrapping(true) in your case, it must be something like this: ui->dateTimeEdit-

QDateTime Conversion

佐手、 提交于 2019-12-11 19:27:53
问题 I need to convert the String variable to QDateTime format my code looks QString date ="Thu Jun 18 2015"; QDateTime tmp = QDateTime::fromString(date,"ddd MMM dd yyyy HH:mm:ss"); But the result is Thu Jan 1 00:00:00 1970 . Later I have to convert this date in to foramt yyyy-MM-dd HH:mm:ss , so as a first step I have convert the string in to QDateTime then I have to convert to the final format, is there anything mistake with the above code? Any help will be appreciated. Thanks Haris 回答1: Your

Convert QDate to seconds

Deadly 提交于 2019-12-02 05:33:30
问题 I take date from QDateTimeEdit and convert it to seconds like this: import time from datetime import datetime date = self.__ui.dateTimeEdit.date().toString("dd/MM/yy") dateString = str(date) seconds = time.mktime(datetime.strptime(dateString, "%d/%m/%y").timetuple()) This works well, but since it looks to long to me, my question is: Is it possible to convert self.__ui.dateTimeEdit.date() directly, without those string conversions? EDIT1 Unfortunately toMSecsSinceEpoch() as falsetru suggested,

Convert QDate to seconds

霸气de小男生 提交于 2019-12-02 01:34:15
I take date from QDateTimeEdit and convert it to seconds like this: import time from datetime import datetime date = self.__ui.dateTimeEdit.date().toString("dd/MM/yy") dateString = str(date) seconds = time.mktime(datetime.strptime(dateString, "%d/%m/%y").timetuple()) This works well, but since it looks to long to me, my question is: Is it possible to convert self.__ui.dateTimeEdit.date() directly, without those string conversions? EDIT1 Unfortunately toMSecsSinceEpoch() as falsetru suggested, doesn't work for me. AttributeError: 'QDateTime' object has no attribute 'toMSecsSinceEpoch' I'm using