qt - QDateTime Conversion -
i need convert string variable qdatetime format
my code looks
qstring date ="thu jun 18 2015"; qdatetime tmp = qdatetime::fromstring(date,"ddd mmm dd yyyy hh:mm:ss");   but result thu jan 1 00:00:00 1970. 
later have convert date in foramt yyyy-mm-dd hh:mm:ss, first step have convert string in qdatetime have convert final format, there mistake above code?
any appreciated.
thanks haris
your date string not include time, while mentioned want one, fail @ least in qt 5.4 . don't know though why epoche outputed, maybe dependant on qt version.
your date format locale dependent. see example doucmentation "ddd" in qdatetime::fromstring:
the abbreviated localized day name (e.g. 'mon' 'sun'). uses qdate::shortdayname().
which unfortunately not clear, while more clear qdatetime::tostring:
the abbreviated localized day name (e.g. 'mon' 'sun'). uses system locale localize name, i.e. qlocale::system().
for example, in locale (german, austria) "ddd" thursday results in "do." different "thu" , makes impossible parse english abbrevations locale.
to ensure using correct locale when reading or writing locale dependent output use qlocale. in case qlocale::todatetime:
qlocale locale(qlocale::english, qlocale::unitedstates); qdatetime dt = locale.todatetime("jun 18 2015", "mmm dd yyyy");   then if want locale dependent output use qlocale::tostring.
Comments
Post a Comment