maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   [Sailfish] Unix timestamp from XML file to string (https://talk.maemo.org/showthread.php?t=92500)

No.User 2014-01-23 22:13

[Sailfish] Unix timestamp from XML file to string
 
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!

coderus 2014-01-23 22:46

Re: [Sailfish] Unix timestamp from XML file to string
 
1. you declaring "date" role, but using "datum". wtf?
2. show your xml

No.User 2014-01-24 15:09

Re: [Sailfish] Unix timestamp from XML file to string
 
Quote:

Originally Posted by coderus (Post 1408560)
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" ) +"  --  "
}


No.User 2014-01-25 10:08

Re:[Sailfish] Unix timestamp from XML file to string
 
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 2014-01-25 10:10

Re: [Sailfish] Unix timestamp from XML file to string
 
show me timestamp showing not correctly

No.User 2014-01-25 11:17

Re: [Sailfish] Unix timestamp from XML file to string
 
This is the timestamp: 1391187600
And the Result is: 31.01.2014 - 17.59

No.User 2014-01-25 11:33

Re: [Sailfish] Unix timestamp from XML file to string
 
1397232000 on the other side gives the intended time. I tried to add some milliseconds but this doesn't help either...

coderus 2014-01-25 13:16

Re: [Sailfish] Unix timestamp from XML file to string
 
its impossible.
new Date(1391187600 * 1000).toString();
showing Fri Jan 31 2014 23:00:00 GMT+0600 (YEKT)

No.User 2014-01-25 15:44

Re: [Sailfish] Unix timestamp from XML file to string
 
It is displayed correctly on the emulator. I only have the offset on my phone. Mybe it is a bug...

coderus 2014-01-25 16:09

Re: [Sailfish] Unix timestamp from XML file to string
 
i'm not using emulator


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

vBulletin® Version 3.8.8