Active Topics

 


Reply
Thread Tools
Posts: 10 | Thanked: 0 times | Joined on Jan 2014
#1
Hi,

I am very new to Qt and just got stuck at a probably very simple problem. The XML file I got contains a date formatted as unix timestamp. How do I get this timestamp into a string?

This is XmlRole:
Code:
XmlRole { name: "date"; query: "date/number()" }
And this is my approach to format it:
Code:
Label {
                id: labelArt
                text: Qt.formatDateTime(Date(model.datum),"dd.mm.YY - hh:mm" ) +"  --  "
}
The result is just the two dashes. Probably the "Date(model.datum)" is not the correct way to do it but I was not able to find how to do in any documentation.

Thanks!

Last edited by No.User; 2014-01-25 at 10:08.
 
coderus's Avatar
Posts: 6,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#2
1. you declaring "date" role, but using "datum". wtf?
2. show your xml
__________________
Telegram | Openrepos | GitHub | Revolut donations
 
Posts: 10 | Thanked: 0 times | Joined on Jan 2014
#3
Originally Posted by coderus View Post
1. you declaring "date" role, but using "datum". wtf?
2. show your xml
Sorry my mistake. I set up my app in German and change the names to english when I posted the code. Forgot to change the second one as well. In my code that is correct, I use the same name.

[Update]
After a lot of try and error I found the mistake. Date alone was not enough, I had to create a new Date and multiply with 1000 since JavaScript expects milliseconds. Now the code works but I get UTC time. I deducted one hour but I guess that is not the correct way to do it. In case anybody knows how to do it correctly please let me know.

Code:
Label {
                id: labelArt
                text: Qt.formatDateTime( new Date(model.date*1000),"dd.mm.YY - hh:mm" ) +"  --  "
}

Last edited by No.User; 2014-01-24 at 17:30. Reason: Solved
 
Posts: 10 | Thanked: 0 times | Joined on Jan 2014
#4
After I deployed the app to my Jolla the time zone was correct but on some dates the time is off by -1 Minute.
So I guess this is still not the correct way to do it. Can anyone tell me what is the right way to format a unix timestamp?

Code:
Qt.formatDateTime( new Date(model.date*1000),"dd.mm.YY - hh:mm" )
 
coderus's Avatar
Posts: 6,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#5
show me timestamp showing not correctly
__________________
Telegram | Openrepos | GitHub | Revolut donations
 
Posts: 10 | Thanked: 0 times | Joined on Jan 2014
#6
This is the timestamp: 1391187600
And the Result is: 31.01.2014 - 17.59
 
Posts: 10 | Thanked: 0 times | Joined on Jan 2014
#7
1397232000 on the other side gives the intended time. I tried to add some milliseconds but this doesn't help either...
 
coderus's Avatar
Posts: 6,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#8
its impossible.
new Date(1391187600 * 1000).toString();
showing Fri Jan 31 2014 23:00:00 GMT+0600 (YEKT)
__________________
Telegram | Openrepos | GitHub | Revolut donations
 
Posts: 10 | Thanked: 0 times | Joined on Jan 2014
#9
It is displayed correctly on the emulator. I only have the offset on my phone. Mybe it is a bug...
 
coderus's Avatar
Posts: 6,436 | Thanked: 12,701 times | Joined on Nov 2011 @ Ängelholm, Sweden
#10
i'm not using emulator
__________________
Telegram | Openrepos | GitHub | Revolut donations
 
Reply


 
Forum Jump


All times are GMT. The time now is 15:31.