Skip to content

DateTime

Qt Base Class: QDateTime

Signature: QDateTime(self) -> None QDateTime(self, arg__1: int, arg__2: int, arg__3: int, arg__4: int, arg__5: int, arg__6: int) -> None QDateTime(self, arg__1: int, arg__2: int, arg__3: int, arg__4: int, arg__5: int, arg__6: int, arg__7: int, arg__8: PySide6.QtCore.Qt.TimeSpec = Instance(Qt.LocalTime)) -> None QDateTime(self, arg__1: int, arg__2: int, arg__3: int, arg__4: int, arg__5: int, arg__6: int, arg__7: int, arg__8: int = Instance(Qt.LocalTime)) -> None QDateTime(self, date: PySide6.QtCore.QDate, time: PySide6.QtCore.QTime) -> None QDateTime(self, date: PySide6.QtCore.QDate, time: PySide6.QtCore.QTime, spec: PySide6.QtCore.Qt.TimeSpec, offsetSeconds: int = 0) -> None QDateTime(self, date: PySide6.QtCore.QDate, time: PySide6.QtCore.QTime, timeZone: Union[PySide6.QtCore.QTimeZone, PySide6.QtCore.QTimeZone.Initialization]) -> None QDateTime(self, other: PySide6.QtCore.QDateTime) -> None

Base classes

Name Children Inherits
QDateTime
PySide6.QtCore
QDateTime(self) -> None

⋔ Inheritance diagram

graph TD
  1473299721328["core.DateTime"]
  1473289002304["QtCore.QDateTime"]
  1473291690208["Shiboken.Object"]
  140713234304496["builtins.object"]
  1473289002304 --> 1473299721328
  1473291690208 --> 1473289002304
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: QDateTime

DateTime funcitons.

Source code in prettyqt\core\_datetime.py
class DateTime(core.QDateTime):
    """DateTime funcitons."""

    def __repr__(self):
        template = super().__repr__().split("(")[1]
        return f"{type(self).__name__}({template}"

    def __str__(self):
        return self.toString("yyyy-MM-dd hh:mm:ss.zzzzzz")

    def __reduce__(self):
        return type(self), (self.date(), self.time(), self.get_timezone())

    def __format__(self, format_spec: constants.DateFormatStr):
        if format_spec in constants.DATE_FORMAT:
            return self.to_format(format_spec)
        return self.toString(format_spec)

    @classmethod
    def from_seconds(cls, seconds: float) -> Self:
        new = cls()
        new.setMSecsSinceEpoch(int(seconds * 1000))
        return new

    def get_value(self) -> datetime.datetime:
        return self.toPython()

    def get_date(self) -> core.Date:
        return core.Date(self.date())

    def get_time(self) -> core.Time:
        return core.Time(self.time())

    def get_timezone(self) -> core.TimeZone:
        return core.TimeZone(self.timeZone())

    def set_timezone(self, zone: str | core.QTimeZone):
        if isinstance(zone, str):
            self.setTimeZone(core.TimeZone(zone))
        else:
            self.setTimeZone(zone)

    def set_time_spec(self, spec: constants.TimeSpecStr | constants.TimeSpec):
        """Set the time specification.

        Args:
            spec: time specification to use
        """
        self.setTimeSpec(constants.TIME_SPEC[spec])

    def get_time_spec(self) -> constants.TimeSpecStr:
        """Return current time specification.

        Returns:
            time specification
        """
        return constants.TIME_SPEC.inverse[self.timeSpec()]

    def to_format(self, fmt: constants.DateFormatStr):
        return self.toString(constants.DATE_FORMAT[fmt])

get_time_spec() -> constants.TimeSpecStr

Return current time specification.

Source code in prettyqt\core\_datetime.py
def get_time_spec(self) -> constants.TimeSpecStr:
    """Return current time specification.

    Returns:
        time specification
    """
    return constants.TIME_SPEC.inverse[self.timeSpec()]

set_time_spec(spec: constants.TimeSpecStr | constants.TimeSpec)

Set the time specification.

Parameters:

Name Type Description Default
spec TimeSpecStr | TimeSpec

time specification to use

required
Source code in prettyqt\core\_datetime.py
def set_time_spec(self, spec: constants.TimeSpecStr | constants.TimeSpec):
    """Set the time specification.

    Args:
        spec: time specification to use
    """
    self.setTimeSpec(constants.TIME_SPEC[spec])