i need to convert date string "28/01/2018" (dd/mm/yyyy) into a Date() in qml.
i'm tried this:
var dateBoard = masterPAGEMAIN.getData();
var locale = Qt.locale()
var someDateTest = new Date()
someDateTest = Date.fromLocaleString(locale, dateBoard, "dd/MM/yyyy");
var test = someDateTest.getDate().toString();
Also saw this: conversione from string , but my problem is that i continue to receive a "NaN" or "Invalid Date", how to can i get Date() from string in qml ?
Thanks
The string passed to fromLocaleString must be in the expected format. Try this code:
var dateBoard = "01/31/2018"
var someDateTest = Date.fromLocaleString(Qt.locale(), dateBoard, "dd/MM/yyyy")
var test = someDateTest.getDate() //nan
Since the string in dateBoard represents a date in MM/dd/yyyy format, fromLocaleString will return an invalid date and getDate nan, accordingly.
Same applies if dateBoard is an empty string, null or undefined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With