Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Get list of future dates?



  • Hi all,

    Not sure I am getting any documentation covering this: how can one get future dates in QML?
    I tried to use javascript - not getting me anywhere (see below). it just adds to date string digit "1"...

    Either I am missing something but I always thought as easy task as this can't be SO complicated;(((
    @
    function populatefuturedates() {
    var today = new Date()
    var tomorrow = today+1
    }
    @
    [edit, code tags added, koahnig]



  • Also tried this below and found that for the current Date() if attempted to get month number it gives me 7 instead of 8...how come??

    @function populatemydates() {
    var day0 = new Date()
    var day0month = day0.getMonth()
    var day1 = new Date(day0.getTime()+86400000)
    var day2 = new Date(day1.getTime()+86400000)
    var day3 = new Date(day2.getTime()+86400000)
    var day4 = new Date(day3.getTime()+86400000)
    var day5 = new Date(day4.getTime()+86400000)
    console.log(day0month)
    }@





  • Try looking at Javascript documentation: "Date Object":http://www.w3schools.com/jsref/jsref_obj_date.asp.
    getMonth() returns value from 0 to 11 so 7 is august.

    edit: too late :)



  • In JavaScript, the Date object is just a number, which is interpreted as having some particular meaning. Read the ecma262r5 spec for the exact semantics, but I believe that it's the number of milliseconds since some epoch. Whenever you do something like "someObject + 1" the JavaScript engine will say: "can I convert the someObject to a primitive value, to which the +1 operation makes sense?" -- and for Date, the answer is yes (actually, for all objects the answer is yes, although in some cases it's rather arbitrary as to whether you get a string back or a number) - since internally it really is just a number.

    If you are writing JavaScript code in QML, it does help to have the ECMA262r5 specification on hand.

    Cheers,
    Chris.


Log in to reply