How to convert st_mtime (which get from stat function) to string or char

后端 未结 3 1405
广开言路
广开言路 2021-01-04 19:41

I need to convert st_mtime to string format for passing it to java layer, i try to use this example http://www.cplusplus.com/forum/unices/10342/ but compiler produce errors

3条回答
  •  忘掉有多难
    2021-01-04 19:56

    use strftime() there's an example in the man page something like:

    struct tm *tm;
    char buf[200];
    /* convert time_t to broken-down time representation */
    tm = localtime(&t);
    /* format time days.month.year hour:minute:seconds */
    strftime(buf, sizeof(buf), "%d.%m.%Y %H:%M:%S", tm);
    printf("%s\n", buf);
    

    Would print the output:

    "24.11.2012 17:04:33"
    

提交回复
热议问题