I'm learning qml and trying to build a basic clock. Now I'm trying to add zeros before the hours, minutes and seconds when they are less than 10. How to do that most effective way?
Here is the code I'm using:
Item {
id: time
width: parent.width
height: 80
property date now: new Date()
property int hours: time.now.getHours()
property int minutes: time.now.getMinutes()
property int seconds: time.now.getSeconds()
property int day: time.now.getDate()
property var month: ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"];
property int month_number: time.now.getMonth() + 1
property int year: time.now.getFullYear()
Text {
text: time.hours + ":" + time.minutes + ":" + time.seconds
font.pixelSize: 48
font.weight: Font.DemiBold
color: "#AEB3C3"
}
Text {
text: time.day + " " + time.month[time.month_number] + " " + time.year + " г."
font.pixelSize: 20
color: "#AEB3C3"
y: 60
}
Timer {
id: updateclock
interval: 1000
running: true
repeat: true
onTriggered: {
time.now = new Date()
}
}
}