How to get the custom date and time format???
2011-07-29 18:55:09
How to format the date and time to this format??
How to get the custom date and time format???
2011-07-29 18:55:09
How to format the date and time to this format??
the class QDateTime provides everything you need.
Qt Code:
To copy to clipboard, switch view to plain text mode
I have tried using the above code, but it fails..
what exactly do you want? create a time format to a string? or convert a string to time format?
Could you please explain with my code above??
ok, I'll try.
you convert a QDateTime (at least I hope it's a QDateTime) into a QString. You use Qt::TextDate as string format. Then you reconvert this string into a QDateTime using a different format ("yyyy-MM-dd hh:mm:ss"). No wonder that fails.
try this one:
Qt Code:
To copy to clipboard, switch view to plain text mode
Can you please, just for once, answer the question put to you. Which do you want; to convert a date/time object to a string, or to convert a string to a date/time object?
As explained by FelixB your code is doomed to fail because the first line produces a string that the second line does not match. If it did what you seem to intend then this is much faster:
and there is no string involved.
"We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.
Bookmarks