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. Save filename by datetime format
Qt 6.11 is out! See what's new in the release blog

Save filename by datetime format

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 5.4k 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.
  • H Offline
    H Offline
    hannao
    wrote on last edited by
    #1

    Hello.
    I need to save csv. filename by current date and time format.
    please tell me how to create it.
    Thanks

    A 1 Reply Last reply
    0
    • H hannao

      Hello.
      I need to save csv. filename by current date and time format.
      please tell me how to create it.
      Thanks

      A Offline
      A Offline
      ambershark
      wrote on last edited by ambershark
      #2

      @hannao

      QFile f(QString("%1.csv").arg(QDateTime::currentDateTime().toString("ddMMyyyy-hhmmss"));
      
      if (file.open(QIODevice::WriteOnly | QIODevice::Text))
      {
         // write your csv data here
      }
      

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      H 1 Reply Last reply
      3
      • A ambershark

        @hannao

        QFile f(QString("%1.csv").arg(QDateTime::currentDateTime().toString("ddMMyyyy-hhmmss"));
        
        if (file.open(QIODevice::WriteOnly | QIODevice::Text))
        {
           // write your csv data here
        }
        
        H Offline
        H Offline
        hannao
        wrote on last edited by
        #3

        @ambershark Thanks
        it work for me
        QDateTime now = QDateTime::currentDateTime();
        QString timestamp = now.toString(QLatin1String("yyyyMMdd-hhmm"));
        QString filename = QString::fromLatin1("/path/%1.csv").arg(timestamp);
        QFile file(filename);
        if(!file.open(QIODevice::WriteOnly | QIODevice::Text))
        {
        // write data
        }
        file.close();

        1 Reply Last reply
        1

        • Login

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