fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. int main() {
  5. char *time_string = "2023-02-30 12:34:56";
  6. struct tm time_struct;
  7. time_t time_value;
  8.  
  9. // Parse the string into a tm struct
  10. if (strptime(time_string, "%Y-%m-%d %H:%M:%S", &time_struct) == NULL) {
  11. printf("Error parsing time string\n");
  12. return 1;
  13. }
  14.  
  15. // Convert the tm struct to a time_t value
  16. time_value = mktime(&time_struct);
  17.  
  18. printf("Time value: %ld\n", time_value);
  19.  
  20. return 0;
  21. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Time value: -1