Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Parse QDateTime from string
Forum Updated to NodeBB v4.3 + New Features

Parse QDateTime from string

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 511 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Creatorczyk
    wrote on 11 Aug 2021, 07:35 last edited by
    #1

    Hi,

    I would like to init object of class QDateTime with string like this

    QString line = "29/04/2021,13:42:12.051000";
    QDateTime dateTime = QDateTime::fromString(line, "dd/MM/yyyy,HH:mm:ss.zzzzz");
    qDebug()<<dateTime.toString();
    

    But in result i got empty string

    ""
    

    How could I parse string?

    J E 2 Replies Last reply 11 Aug 2021, 07:45
    0
    • C Creatorczyk
      11 Aug 2021, 07:35

      Hi,

      I would like to init object of class QDateTime with string like this

      QString line = "29/04/2021,13:42:12.051000";
      QDateTime dateTime = QDateTime::fromString(line, "dd/MM/yyyy,HH:mm:ss.zzzzz");
      qDebug()<<dateTime.toString();
      

      But in result i got empty string

      ""
      

      How could I parse string?

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 11 Aug 2021, 07:45 last edited by
      #2

      @Creatorczyk
      I don't think you can with 5z's as your milliseconds
      Time only supports
      6b8cc151-0255-4db5-b22d-140f19b53776-image.png

      so you'll have to truncate the string


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • C Creatorczyk
        11 Aug 2021, 07:35

        Hi,

        I would like to init object of class QDateTime with string like this

        QString line = "29/04/2021,13:42:12.051000";
        QDateTime dateTime = QDateTime::fromString(line, "dd/MM/yyyy,HH:mm:ss.zzzzz");
        qDebug()<<dateTime.toString();
        

        But in result i got empty string

        ""
        

        How could I parse string?

        E Offline
        E Offline
        eyllanesc
        wrote on 11 Aug 2021, 07:49 last edited by
        #3

        @Creatorczyk the "z" is related to the number of milliseconds so "z", "zz" and "zzz" make sense but more not since for example "1" equals "100" milliseconds, "11" equals "110" milliseconds but "1111" exceeds millisecond.

        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

        1 Reply Last reply
        2
        • S Offline
          S Offline
          SilentWolf
          wrote on 11 Aug 2021, 14:42 last edited by
          #4

          @Creatorczyk said in Parse QDateTime from string:

          QString line = "29/04/2021,13:42:12.051000";
          QDateTime dateTime = QDateTime::fromString(line, "dd/MM/yyyy,HH:mm:ss.zzzzz");
          qDebug()<<dateTime.toString();

          you should shorten the text: 3 characters after "."
          QString line = "29/04/2021,13:42:12.051";
          QDateTime dateTime = QDateTime::fromString(line, "dd/MM/yyyy,HH:mm:ss.zzz");
          qDebug()<<dateTime.toString();

          1 Reply Last reply
          0

          1/4

          11 Aug 2021, 07:35

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved