【pyqt5】QdateTimeEdit(日期时间)
返回当前日期和时间设置
from PyQt5 import QtCore, QtWidgets class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.setWindowModality(QtCore.Qt.WindowModal)
Dialog.resize(690, 437)
Dialog.setAutoFillBackground(True)
Dialog.setSizeGripEnabled(True)
self.calendarWidget = QtWidgets.QCalendarWidget(Dialog)
self.calendarWidget.setGeometry(QtCore.QRect(230, 30, 431, 291))
self.calendarWidget.setObjectName("calendarWidget")
self.dateEdit = QtWidgets.QDateEdit(Dialog)
self.dateEdit.setGeometry(QtCore.QRect(30, 80, 171, 22))
self.dateEdit.setObjectName("dateEdit")
self.dateTimeEdit = QtWidgets.QDateTimeEdit(Dialog)
self.dateTimeEdit.setEnabled(True)
self.dateTimeEdit.setGeometry(QtCore.QRect(10, 190, 211, 31))
self.dateTimeEdit.setToolTip("")
self.dateTimeEdit.setWrapping(False)
self.dateTimeEdit.setFrame(True) #边框可见
self.dateTimeEdit.setReadOnly(False) #设置只读模式
self.dateTimeEdit.setButtonSymbols(QtWidgets.QAbstractSpinBox.UpDownArrows)
self.dateTimeEdit.setSpecialValueText("")
self.dateTimeEdit.setKeyboardTracking(True)
self.dateTimeEdit.setCurrentSection(QtWidgets.QDateTimeEdit.DaySection)
self.dateTimeEdit.setCalendarPopup(True)
self.dateTimeEdit.setCurrentSectionIndex(3)
self.dateTimeEdit.setTimeSpec(QtCore.Qt.LocalTime)
self.dateTimeEdit.setObjectName("dateTimeEdit") self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog")) if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
UI文件
main文件中设置(将获取当前日期时间的代码放在main文件中,避免QT设计师更改界面时 代码改动)
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5 import QtWidgets
from Ui_QDataTimeEdit import Ui_Dialog class Dialog(QDialog, Ui_Dialog):
def __init__(self, parent=None):
super(Dialog, self).__init__(parent)
self.setupUi(self)
self.dateTimeEdit.setDateTime(QDateTime.currentDateTime())
self.dateEdit.setDate(QDate.currentDate()) if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
ui = Dialog()
ui.show()
sys.exit(app.exec_())
一些常用的技巧:
self.dateTimeEdit = QtWidgets.QDateTimeEdit(self.widget)
self.dateTimeEdit.setFrame(False) #去除边框
self.dateTimeEdit.setDate(QtCore.QDate(2018, 10, 25)) #设置日期
self.dateTimeEdit.setTime(QtCore.QTime(11, 0, 0)) #设置时间11:00
self.dateTimeEdit.setObjectName("dateTimeEdit") #设置对象名称 """
方式1:
from PyQt5.QtCore import QDate,QTime
##设置为当前日期
self.dateTimeEdit.setDateTime(QDate.currentDate())
##设置为当前时间
self.dateTimeEdit.setDateTime(QTime.currentTime()) 方式2:
from PyQt5.QtCore import QDateTime
##设置当前日期和时间
self.dateTimeEdit.setDateTime(QDateTime.currentDateTime())
"""
##同理设置dataEdit是一样的
from PyQt5.QtCore import QDate
self.dateEdit.setDate(QDate.currentDate())
打印出不同格式的日期和时间
from PyQt5.QtCore import QDate, QTime, QDateTime, Qt """返回当前日期"""
now = QDate.currentDate()
print(now) #PyQt5.QtCore.QDate(2018, 12, 3)
print(now.toString()) #周一 12月 3 2018
print(now.toString(Qt.ISODate)) #2018-12-03
print(now.toString(Qt.DefaultLocaleLongDate)) #2018年12月3日, 星期一 """返回当前日期和时间"""
datetime = QDateTime.currentDateTime()
print(datetime) #PyQt5.QtCore.QDateTime(2018, 12, 3, 15, 9, 41, 976)
print(datetime.toString()) #周一 12月 3 15:09:41 2018
print(datetime.toString(Qt.ISODate)) #2018-12-03T15:09:41
print(datetime.toString(Qt.DefaultLocaleLongDate)) #2018年12月3日, 星期一 15:09:41 """返回当前时间"""
time = QTime.currentTime()
print(time) #PyQt5.QtCore.QTime(15, 12, 9, 980)
print(time.toString()) #15:12:09
print(time.toString(Qt.ISODate)) #15:12:09
print(time.toString(Qt.DefaultLocaleLongDate)) #15:12:09
【pyqt5】QdateTimeEdit(日期时间)的更多相关文章
- PyQt(Python+Qt)学习随笔:QDateTimeEdit日期时间编辑部件
专栏:Python基础教程目录 专栏:使用PyQt开发图形界面Python应用 专栏:PyQt入门学习 老猿Python博文目录 老猿学5G博文目录 Designer输入部件中,Date/Time E ...
- EasyUI datagrid 日期时间格式化
EasyUI datagrid中显示日期时间时,会显示为以下不太直观的数值: 添加以下JavaScript脚本,然后在field中添加 formatter: DateTimeFormatter 即可. ...
- POCO库——Foundation组件之日期时间DateTime
日期时间DateTime:内部提供多个设计计时器.日期.时区.时间戳等: Clock.h :Clock时钟计时类,_clock:Int64类型时钟值,CLOCKVAL_MIN.CLOCKVAL_MAX ...
- db2 日期时间格式
db2日期和时间常用汇总 1.db2可以通过SYSIBM.SYSDUMMY1.SYSIBM.DUAL获取寄存器中的值,也可以通过VALUES关键字获取寄存器中的值. SELECT 'HELLO DB2 ...
- Angularjs在控制器(controller.js)的js代码中使用过滤器($filter)格式化日期/时间实例
Angularjs内置的过滤器(filter)为我们的数据信息格式化提供了比较强大的功能,比如:格式化时间,日期.格式化数字精度.语言本地化.格式化货币等等.但这些过滤器一般都是在VIEW中使用的,比 ...
- MySQL学习笔记八:日期/时间的处理
MySQL日期时间的处理,在其官网文档上都有详细的阐述,想了解更多的同学可自行查阅. 1.查询当前日期时间:函数有now(),localtime(),current_timestamp(),sysda ...
- Java日期时间操作的一些方法
1. 获得Calendar实例: Calendar c = Calendar.getInstance(); 2. 定义日期/时间的格式: SimpleDateFormat sdf =new Simpl ...
- mysql与oracle的日期/时间函数小结
前言 本文的日期/时间全部格式化为”2016-01-01 01:01:01“形式: MONITOR_TIME为数据库表字段: 字符串与日期/时间相互转换函数 Oracle 日期/时间转字符串函数:to ...
- js 日期时间排序 数组
不多说直接show代码 var timeArr=[ {'id':'A01','date':'2016-04-20 23:22:11'}, {'id':'A02','date':'2016-04-21 ...
- sql server日期时间转字符串
一.sql server日期时间函数Sql Server中的日期与时间函数 1. 当前系统日期.时间 select getdate() 2. dateadd 在向指定日期加上一段时间的基 ...
随机推荐
- 使用 requests 配置代理服务
(1) 如果我们一直用同一个IP去请求同一个网站上的网页,久了之后可能会被该网站服务器屏蔽,因此我们可以使用代理IP来发起请求,代理实际上指的就是代理服务器(2) 当我们使用代理IP发起请求时,服务器 ...
- 自己搭建CDN服务器静态内容加速-LuManager CDN使用教程
为什么要自己来搭建一个CDN服务器实现网站访问加速?一是免费CDN服务稳定性和加速效果都不怎么行:二是用国内的付费CDN服务价格贵得要死,一般的草根站长无法承受:三是最现实的问题国内的CDN要求域名B ...
- DLL注入之Appinit_Dlls
AppInit_DLLs is a mechanism that allows an arbitrary list of DLLs to be loaded into each user mode p ...
- 【软件分析与挖掘】An Empirical Study of Bugs in Build Process
摘要 对软件构建过程中所产生的错误(build process bugs)进行实证研究. 5个开源项目:CXF, Camel, Felix,Struts, and Tuscany. 把build pr ...
- 深入学习Make命令和Makefile(下)
https://www.zybuluo.com/lishuhuakai/note/209300 make是Linux下的一款程序自动维护工具,配合makefile的使用,就能够根据程序中模块的修改情况 ...
- 深入学习Make命令和Makefile(上)
https://www.zybuluo.com/lishuhuakai/note/209302 深入学习Make命令和Makefile(上) make是Linux下的一款程序自动维护工具,配合make ...
- 题目1448:Legal or Not(有向无环图判断——拓扑排序问题)
题目链接:http://ac.jobdu.com/problem.php?pid=1448 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- 利用Jenkins未授权获取服务器权限--Docker还来干扰--一次渗透的经历
Jenkins获取权限的过程 Jenkins存在未授权访问漏洞 Jenkins存在未授权访问漏洞,且项目具有读取权限,通过项目的日志获取到一个账号密码,尝试登录成功,打开控制台成功. 备注:控制台一般 ...
- vue生成路由实例, 使用单个vue文件模板生成路由
一.vue-loader与vue-router配合 $ cnpm install vue-router --save 二.生成vue-webpack模板 $ vue init webpack-simp ...
- 二、Laya学习笔记 ---- Laya中如何新建一个场景UI并使用
因为我之前是用Egret的,Egret是场景皮肤HomeSceneSkin.exml,然后在场景代码HomeScene代码中为该场景赋值皮肤this.skinName = "HomeScen ...