Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT reformat date time string

Tags:

c++

qt

I've got a QString that contains a date in the following format:

2014-03-18 09:30:36

How can i format it to: HH:mm?

like image 405
Alosyius Avatar asked Jun 20 '26 04:06

Alosyius


1 Answers

You can use QDateTime::fromString and QDateTime::toString methods:

QString dateStr = "2014-03-18 09:30:36";
QString fmt = "yyyy-MM-dd hh:mm:ss";
QDateTime dt = QDateTime::fromString(dateStr, fmt);
QString timeStr = dt.toString("hh:mm");
like image 70
hank Avatar answered Jun 21 '26 18:06

hank



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!