Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 2 Support (Qt 5) › Problem with date.toLocaleString with locale and options

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #19428

    Eric

    Hello,

    I’m trying to get the following to diplay the date and time without the timezone:

    var d = new Date()
    console.debug(d.toLocaleString(Qt.locale(“en-US”))

    which currently returns

    ”Friday, June 1, 2018 9:17:44 AM Alaskan Daylight Time”.

    I’d like to change how this is returned, primarily I want to remove the timezone information. However, when I try to use options as described at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString, I get an invalid date format error.

    If I do something like (but with all the output I want)

    console.debug(d.toLocaleString(Qt.locale(“en-US”), “M-yyyy”)

    It seems to remove the auto-format that I want from toLocaleString.

    Is there any way to pass options so that only the actual date/time elements I want to display are actually displayed but the auto-format is preserved?

    Thank you,
    Eric

    #19430

    Günther
    Felgo Team

    Hi,

    QML is does not always support JavaScript in 100% the same way as in the browser. For example, the QML toLocaleDateString method for date types does not take options as the second argument, but a format identifier.

    You can have a look at the Qt docs linked above, as well as this example:

     var d = new Date()
    
          // show date format for locale
          console.log("FORMAT en-US: "+Qt.locale("de-AT").dateTimeFormat())
          console.log("FORMAT de-AT: "+Qt.locale("de-AT").dateTimeFormat())
    
          // default format
          console.debug(d.toLocaleString(Qt.locale("en-US"), Qt.locale("en-US").dateTimeFormat()))
          console.debug(d.toLocaleString(Qt.locale("de-AT"), Qt.locale("de-AT").dateTimeFormat()))
    
          // no timezone
          console.debug("No timezone: "+d.toLocaleString(Qt.locale("en-US"),"dddd, d. MMMM yyyy HH:mm:ss"))

    Best,
    Günther

Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded