c++ - MongoDB bson_date_t to local time -
i appended date mongodb this
bson_append_date(b,"uploaddate",(bson_date_t)1000*time(null));
do remember append "milliseconds since epoch utc" , saved 2014-06-27 06:11:56
now reading out , giving milliseconds (1403852029
) right. want convert local time. tried use localtime function of c++ did success time returned mongodb in int64_t.
if(bson_iterator_type(&it)==bson_date) bson_date_t date_it = bson_iterator_date( &it );
where bson_date_t typedef int64_t bson_date_t;
. can tell me how can local time milliseconds.
getting valid time_t work localtime should opposite of doing in forward conversion:
bson_append_date(b,"uploaddate",(bson_date_t)1000*time(null));
to have workable time_t, should following:
time_t rawtime = (time_t)(bson_iterator_date( &it ) / 1000); struct tm * timeinfo = localtime (&rawtime);
Comments
Post a Comment