本页内容

date QML Value Type

一个日期值。更多...

Import Statement: import QtQml

详细说明

date 类型指代一个日期值,其中包含具体时间。

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

要创建一个date 值,请将其指定为“YYYY-MM-DDThh:mm:ss.zzzZ”字符串。 (T 为字面量,YYYY 为完整年份,MM 和 DD 分别为月份和日期,hh、mm 和 ss 分别为小时、分钟和秒,.zzz 为毫秒,Z 为时区偏移量。 字母 T 及其后面的时间部分是可选的。如果省略它们,该日期将被视为 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 的任何QDate 或QDateTime 值都会自动转换为date 值,反之亦然。但请注意,将QDate 进行转换将导致结果为 UTC 时间的一天开始时间,而在某些其他时区,这将对应不同的日期。 通常,通过QDateTime 显式转换QDate 会更稳健,具体方法是指定当地时间或相关时区,并选择一个可靠存在的特定时刻(如正午),因为夏令时转换会在一天的起始或结束附近跳过一小时。

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

另请参阅 QML Date 对象和QML 值类型。

© 2026 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.