Save filename by datetime format
Solved
General and Desktop
-
Hello.
I need to save csv. filename by current date and time format.
please tell me how to create it.
ThanksQFile f(QString("%1.csv").arg(QDateTime::currentDateTime().toString("ddMMyyyy-hhmmss")); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { // write your csv data here }
-
QFile f(QString("%1.csv").arg(QDateTime::currentDateTime().toString("ddMMyyyy-hhmmss")); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { // write your csv data here }
@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();