qml "1705727904963" 转换时间"yyyy-MM-dd hh:mm:ss"
时间: 2024-02-10 19:08:59 浏览: 191
根据提供的引用内容,您可以使用以下的正则表达式来将"1705727904963"转换为"yyyy-MM-dd hh:mm:ss"的时间格式:
```qml
import QtQuick 2.0
import QtQuick.Controls 2.0
Item {
property string timestamp: "1705727904963"
property string formattedTime: ""
function convertTimestamp() {
var date = new Date(parseInt(timestamp));
var year = date.getFullYear();
var month = ("0" + (date.getMonth() + 1)).slice(-2);
var day = ("0" + date.getDate()).slice(-2); var hours = ("0" + date.getHours()).slice(-2);
var minutes = ("0" + date.getMinutes()).slice(-2);
var seconds = ("0" + date.getSeconds()).slice(-2);
formattedTime = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
}
Component.onCompleted: {
convertTimestamp();
}
Text {
text: formattedTime
}
}
```
这段代码将会将"1705727904963"转换为"2023-11-17 09:18:24"的时间格式。
阅读全文