QByteArray Datetime convert
Solved
General and Desktop
-
Hi,
I have :
QByteArray dateTime = "20230326082227";
it possible in some simple way convert to format:
"2023-03-26 08:22:27"
?
-
@Damian7546 See if this works for you:
QString dateTime = "20230326082227"; QDateTime date = QDateTime::fromString(dateTime,"yyyyMMddHHmmss"); dateTime = date.toString("yyyy-MM-dd HH:mm:ss"));
This this for more information:
QDateTime::fromString() -
@Damian7546
Just pick out the character sequences as you want them. The first is 4 characters (2023
), the next is 2 characters (03
), and so on. Use QString::mid() or QString::sliced() for this. Then join the extracted strings back up to your desired output format. -
@Damian7546 See if this works for you:
QString dateTime = "20230326082227"; QDateTime date = QDateTime::fromString(dateTime,"yyyyMMddHHmmss"); dateTime = date.toString("yyyy-MM-dd HH:mm:ss"));
This this for more information:
QDateTime::fromString() -