开发者

Is there a function like asctime_s() that works for SYSTEMTIME structures in windows?

开发者 https://www.devze.com 2023-01-05 06:11 出处:网络
I know I can do this if I have a struct tm structure, but what if I want to do the same thing with a SYSTEMTIME.I could do this m开发者_开发百科anually but just wondering if there\'s function that doe

I know I can do this if I have a struct tm structure, but what if I want to do the same thing with a SYSTEMTIME. I could do this m开发者_开发百科anually but just wondering if there's function that does this already.

Thanks

 void PrintTimeSCII(struct tm *time)
 {
     char timebuf[26] = {0};

     asctime_s(timebuf, 26, time);
    printf("%s\n", timebuf);
 }


GetDateFormat can be used for this. It can format the date using the appropriate format for a given locale. Below code shows how to use it for the user's default locale, in short format.

char timebuf[26];
GetDateFormat(LOCALE_USER_DEFAULT, 
              DATE_SHORTDATE,
              &sysTime,
              NULL,
              timebuf, 
              ARRAYSIZE(timebuf));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号