有没有像asctime_s(函数),在窗户SYSTEMTIME结构的工作原理? [英] Is there a function like asctime_s() that works for SYSTEMTIME structures in windows?

查看:199
本文介绍了有没有像asctime_s(函数),在窗户SYSTEMTIME结构的工作原理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如果我想要做同样的事情用SYSTEMTIME我能做到这一点,如果我有一个结构TM结构,但什么。我可以手动做,但只是想知道如果有函数,已经做了这个。

感谢

 无效PrintTimeSCII(结构TM *时间)
 {
     烧焦timebuf [26] = {0};     asctime_s(timebuf,26,时间);
    的printf(%S \\ n,timebuf);
 }


解决方案

GetDateFormat 可以用于此目的。它可以使用适当的格式为给定的区域进行格式化的日期。低于code展示了如何使用它为用户的默认语言环境,短格式。

 字符timebuf [26];
GetDateFormat(LOCALE_USER_DEFAULT,
              DATE_SHORTDATE,
              &安培; SYSTIME,
              空值,
              timebuf,
              ARRAYSIZE(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);
 }

解决方案

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

这篇关于有没有像asctime_s(函数),在窗户SYSTEMTIME结构的工作原理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆