src/lib/btime.c
utime_t str_to_utime(char *str)
{
   struct tm tm;
   time_t time;

   /* Check for bad argument */
   if (!str || *str == 0) {
      return 0;
   }

   if (sscanf(str, "%d-%d-%d %d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
                                        &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
      return 0;
   }
   if (tm.tm_mon > 0) {
      tm.tm_mon--;
   } else {
      return 0;
   }
   if (tm.tm_year >= 1900) {
      tm.tm_year -= 1900;
   } else {
      return 0;
   }
   tm.tm_wday = tm.tm_yday = 0;
   tm.tm_isdst = -1;
   time = mktime(&tm);
   if (time == -1) {
      time = 0;
   }
   return (utime_t)time;
}
/* Convert standard time string yyyy-mm-dd hh:mm:ss to Unix time */
Convert standard time string yyyy-mm-dd hh:mm:ss to Unix time
Convert standard time string yyyy - mm - dd hh : mm : ss to Unix time
utime_t str_to_utime(char *str)
{
   struct tm tm;
   time_t time;
   if (!str || *str == 0) {
      return 0;
   }
   if (sscanf(str, "%d-%d-%d %d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
                                        &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
      return 0;
   }
   if (tm.tm_mon > 0) {
      tm.tm_mon--;
   } else {
      return 0;
   }
   if (tm.tm_year >= 1900) {
      tm.tm_year -= 1900;
   } else {
      return 0;
   }
   tm.tm_wday = tm.tm_yday = 0;
   tm.tm_isdst = -1;
   time = mktime(&tm);
   if (time == -1) {
      time = 0;
   }
   return (utime_t)time;
}
utime_t str_to_utime ( char * str ) { struct tm tm ; time_t time ; if ( ! str || * str == 0 ) { return 0 ; } if ( sscanf ( str , " " , & tm . tm_year , & tm . tm_mon , & tm . tm_mday , & tm . tm_hour , & tm . tm_min , & tm . tm_sec ) != 6 ) { return 0 ; } if ( tm . tm_mon > 0 ) { tm . tm_mon -- ; } else { return 0 ; } if ( tm . tm_year >= 1900 ) { tm . tm_year -= 1900 ; } else { return 0 ; } tm . tm_wday = tm . tm_yday = 0 ; tm . tm_isdst = -1 ; time = mktime ( & tm ) ; if ( time == -1 ) { time = 0 ; } return ( utime_t ) time ; }
Convert standard time string yyyy-mm-dd hh:mm:ss to Unix time
Convert standard time string yyyy - mm - dd hh : mm : ss to Unix time
/* Check for bad argument */