How to use _strtime_s and _strdate_s to get OS time and date in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
    _tzset(); // Set time zone

    char tm[9];

    errno_t err = _strtime_s(tm, 9);
    if (err) {
        printf("_strdate_s error");
        exit(1);
    }
    printf("OS time: %s\n", tm);
    err = _strdate_s(tm, 9);
    if (err) {
        printf("_strdate_s error");
        exit(1);
    }
    printf("OS date: %s\n", tm);

    char ch = getchar();

    return 0;
}
 



/*
run:

OS time: 11:47:04
OS date: 04/08/22

*/

 



answered Apr 8, 2022 by avibootz
edited Apr 8, 2022 by avibootz

Related questions

1 answer 214 views
214 views asked Sep 7, 2014 by avibootz
1 answer 191 views
3 answers 116 views
1 answer 112 views
1 answer 144 views
1 answer 109 views
...