from PyQt6.QtCore import QDate, QTime, QDateTime, Qt
now = QDate.currentDate()
print(now.toString(Qt.DateFormat.ISODate)) #2022-01-11 print(now.toString(Qt.DateFormat.RFC2822Date)) #11 Jan 2022
datetime = QDateTime.currentDateTime()
print(datetime.toString()) #Tue Jan 11 22:04:52 2022
time = QTime.currentTime() print(time.toString(Qt.DateFormat.ISODate)) #22:04:52
UTC时间
1 2 3 4 5 6 7 8
from PyQt6.QtCore import QDateTime, Qt
now = QDateTime.currentDateTime()
print('Local datetime: ', now.toString(Qt.DateFormat.ISODate)) #Local datetime: 2022-01-11T22:11:31 print('Universal datetime: ', now.toUTC().toString(Qt.DateFormat.ISODate)) #Universal datetime: 2022-01-11T14:11:31Z print(f'The offset from UTC is: {now.offsetFromUtc()} seconds') #The offset from UTC is: 28800 seconds #本例获取了标准时间和本地时间。