Qt/C++ - Convert string timestamp to uint -
i want create date timestamp in char*.
so i'm trying convert int atoi() or toint() don't it.
qdebug() << atoi("1478790756754"); /* give 2147483647 */ qstring tmp = "1478790756754"; qdebug() << tmp.toint(); /* give 0 */
the aim date, datetime.settime_t() example.
your timestamp seems in milliseconds since 1.1.1970 format. doesn't fit 32-bit integer, int
type on architecture.
the solution simple: convert type larger value range, i.e. long long
:
qstring tmp = "1478790756754"; qdatetime date = qdatetime::frommsecssinceepoch(tmp.tolonglong());
qstring
's conversion functions have out parameter pointer bool
. can pass bool variable , test check if conversion successful.
Comments
Post a Comment