date QML Value Type

日期值。更多

详细说明

date 类型指的是日期值,包括当天的时间。

date 类型的属性默认为无效值。

要创建date 值,请将其指定为 "YYYY-MM-DDThh:mm:ss.zzzzZ "字符串。(T 是字面意义,YYYY 是整年数字,MM 和 DD 是月和日数字,hh、mm 和 ss 是时、分和秒,.zzz 是毫秒,Z 是时区偏移。T 和后面的时间是可选项。如果省略,日期将作为UTC 日的起始日期处理,而UTC 日在某些时区是其他日期的起始日期。包含 T 时,可以省略 :ss.zzz 或 .zzz 部分。无论是否省略,都可以省略区域偏移,在这种情况下使用当地时间)。例如

MyDatePicker { minDate: "2000-01-01 0:0"; maxDate: "2020-12-31 23:59" }

要读取 C++ 扩展类返回的日期值,请使用Qt.formatDate() 和Qt.formatDateTime() 。

与 C++ 整合时,请注意任何从 C++ 传入 QML 的 QDateQDateTime 值都会自动转换为date 值,反之亦然。但要注意的是,转换QDate 会导致 UTC 的起始日,而在某些其他时区的起始日是不同的。通常更稳健的做法是通过QDateTime 明确转换QDate ,指定当地时间或相关时区,并选择可靠的一天中的某个时间(如正午)(夏令时转换跳过一小时,接近一天的一端或另一端)。

这种值类型由 QML 语言提供。它可以隐式转换为Date 对象。

另请参阅 QML Date objectQML 值类型

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.