是否有像 asctime_s() 这样的函数适用于 Windows 中的 SYSTEMTIME 结构?

发布于 2024-09-06 22:10:11 字数 273 浏览 2 评论 0原文

我知道如果我有一个 struct tm 结构我可以做到这一点,但是如果我想用 SYSTEMTIME 做同样的事情怎么办?我可以手动执行此操作,但只是想知道是否已经有函数可以执行此操作。

谢谢

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

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

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 manually 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);
 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拔了角的鹿 2024-09-13 22:10:11

GetDateFormat 可用于此目的。它可以使用适合给定区域设置的适当格式来格式化日期。下面的代码以短格式显示了如何将其用于用户的默认区域设置。

char timebuf[26];
GetDateFormat(LOCALE_USER_DEFAULT, 
              DATE_SHORTDATE,
              &sysTime,
              NULL,
              timebuf, 
              ARRAYSIZE(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));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文