Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. About using QDateTime::fromString
Forum Updated to NodeBB v4.3 + New Features

About using QDateTime::fromString

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 3.0k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    stabber
    wrote on last edited by
    #1

    I wanna translate time string from sqlite to QDateTime , but It seamed failed , here's the code :
    @

    QDateTime date = QDateTime::fromString( "2013-1-12 14:53:42" , "yyyy-MM-dd hh:mm:ss" );
    QString strDate,strTime;
    do
    {
    strDate = date.date().toString();//empty
    strTime = date.time().toString();//empty
    } while (false);
    @

    what's wrong?

    1 Reply Last reply
    0
    • H Offline
      H Offline
      holygirl
      wrote on last edited by
      #2

      Try using
      @
      date.toString("yyyy-MM-dd");
      @

      instead of

      @
      date.date().toString();
      @

      and to obtain the time value, use

      @
      date.toString("hh:mm:ss");
      @

      I haven't tried it on my computer yet.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stabber
        wrote on last edited by
        #3

        @
        strDate = date.toString("yyyy-MM-dd"); //empty
        strTime = date.toString("hh:mm:ss");//empty
        @
        and
        @
        strDate = date.date().toString("yyyy-MM-dd");//empty
        strTime = date.time().toString("hh:mm:ss");//empty
        @

        1 Reply Last reply
        0
        • H Offline
          H Offline
          holygirl
          wrote on last edited by
          #4

          From what I understood, you are trying to retrieve a string from the database and convert it to QDateTime format. Then, why you are converting it back to a string to check for it's emptiness?
          Even if you must do that, you can simply use @strDate = date.toString("yyyy-MM-dd"); //empty@

          and @strTime = date.toString("hh:mm:ss");//empty@

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stabber
            wrote on last edited by
            #5

            has fixed , that's should be follow code:
            @
            QDateTime date = QDateTime::fromString( "2013-1-12 14:53:42" , "yyyy-M-d h:m:s" );
            QString strDate,strTime;
            do
            {
            strDate = date.date().toString();//empty
            strTime = date.time().toString();//empty
            } while (false);
            @

            1 Reply Last reply
            0

            • Login

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