-6

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

Anis_Stack
  • 3,306
  • 4
  • 30
  • 53
  • 5
    You've already asked this question here, in the same kind of structure, with no C code whatsoever. Publish your code - where is your input string allocated, and where do you want to write the output string? – barak manos Nov 14 '14 at 09:42
  • please read carefully the question is not the same !!!!!!!!! – Anis_Stack Nov 14 '14 at 09:48
  • So here is an answer that is as technically detailed as your question: Scan the input string from left to right, and replace every occurrence of a `T` character or a `-` character with a space character. – barak manos Nov 14 '14 at 09:55

2 Answers2

1

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
jmajnert
  • 418
  • 4
  • 8
0

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);
}
Anis_Stack
  • 3,306
  • 4
  • 30
  • 53
  • 3
    First of all, publish that in the question, not as a separate answer. Second, if it works fine, then what's the question to begin with? – barak manos Nov 14 '14 at 10:05
  • at the first time I don't have the response for that, when any body don't want to answer I search that in other forum – Anis_Stack Nov 14 '14 at 10:16