inlib  1.2.0
/Users/barrand/private/dev/softinex/old/inexlib-1.2/inlib/inlib/s2time
Go to the documentation of this file.
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
00002 // See the file inlib.license for terms.
00003 
00004 #ifndef inlib_s2time
00005 #define inlib_s2time
00006 
00007 #include <ctime>
00008 #include <string>
00009 #include <cstdio> //sscanf
00010 
00011 namespace inlib {
00012 
00013 inline bool s2time(const std::string& a_string,time_t& a_time) {
00014   int yy, mm, dd, hh, mi, ss;
00015   if(::sscanf(a_string.c_str(),
00016               "%d-%d-%d %d:%d:%d",
00017               &yy,&mm,&dd,&hh,&mi,&ss)!=6) {a_time = 0;return false;}
00018   struct tm tp;
00019   tp.tm_year  = yy-1900;
00020   tp.tm_mon   = mm-1;
00021   tp.tm_mday  = dd;
00022   tp.tm_hour  = hh;
00023   tp.tm_min   = mi;
00024   tp.tm_sec   = ss;
00025   tp.tm_isdst = 0;
00026   a_time  = ::mktime(&tp);
00027   return true;
00028 }
00029 
00030 }
00031 
00032 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines