Convert QDate to seconds

前端 未结 2 629
感情败类
感情败类 2021-01-23 00:06

I take date from QDateTimeEdit and convert it to seconds like this:

import time
from datetime import datetime

date = self.__ui.dateTimeEdit.date().         


        
2条回答
  •  粉色の甜心
    2021-01-23 01:00

    Use QDateTime.toMSecsSinceEpoch:

    >>> import PyQt4.QtCore
    >>> d = PyQt4.QtCore.QDateTime(2014, 2, 20, 17, 10, 30)
    >>> d.toMSecsSinceEpoch() / 1000
    1392883830L
    

    UPDATE

    Alternative using QDateTime.toTime_t:

    >>> d = PyQt4.QtCore.QDateTime(2014, 2, 20, 17, 10, 30)
    >>> d.toTime_t()
    1392883830L
    

提交回复
热议问题