I'm trying to convert time from an ISO8601 timestamp.
I want to remove "T" from timestamp exemple :
"0001-01-01T17:45:33" --> "0001-01-01 17:45:33"
this conversion is useful to convert timestamp to epoch time
I'm trying to convert time from an ISO8601 timestamp.
I want to remove "T" from timestamp exemple :
"0001-01-01T17:45:33" --> "0001-01-01 17:45:33"
this conversion is useful to convert timestamp to epoch time
Have you looked at
char *strptime(const char *s, const char *format, struct tm *tm);
from time.h
?
For example:
#include<stdio.h>
#define __USE_XOPEN
#include<time.h>
int main(){
char newtime[100];
const char *time="0001-01-01T17:45:33";
struct tm tm_;
strptime(time,"%FT%T",&tm_);
strftime(newtime,100,"%F %T",&tm_);
printf("%s\n",newtime);
printf("Epoch time:%d\n",(int)mktime(&tm_));
return 0;
}
Output:
1-01-01 17:45:33
Epoch time:-1
I teste with this code, it works fine for me
#include <stdio.h>
#include <string.h>
int main() {
char string[] = {"0001-01-01T17:45:33\0"};
char *temp;
temp = strchr(string, 'T') ;
*temp= ' ';
printf("%s\n", temp);
printf("%s\n", string);
}