Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 在MSVC 6.0中获取系统日期_Windows_Date_System - Fatal编程技术网

Windows 在MSVC 6.0中获取系统日期

Windows 在MSVC 6.0中获取系统日期,windows,date,system,Windows,Date,System,我试图在MSVC++6.0编译器上的C程序中获取系统日期。我正在使用系统调用: 系统(“日期/T”)(输出为例如2008年10月13日,这是我系统上的日期,格式为我设置的格式) 但这会将日期打印到i/o控制台 我如何使这个日期成为上述系统调用返回的日期,并将其作为字符串值存储到代码中定义的字符串中? 或 是否有其他API可用于获取上述格式的日期(2008年10月13日或2008年10月13日) -AD使用API函数有两种方法可以做到这一点,两种方法是和 我想提供一些例子,但恐怕目前手头没有Win

我试图在MSVC++6.0编译器上的C程序中获取系统日期。我正在使用系统调用:

系统(“日期/T”)(输出为例如2008年10月13日,这是我系统上的日期,格式为我设置的格式)

但这会将日期打印到i/o控制台

我如何使这个日期成为上述系统调用返回的日期,并将其作为字符串值存储到代码中定义的字符串中? 或

是否有其他API可用于获取上述格式的日期(2008年10月13日或2008年10月13日)


-AD

使用API函数有两种方法可以做到这一点,两种方法是和


我想提供一些例子,但恐怕目前手头没有Win32编译器。希望以上文档中的示例足够了。

有几种方法可以使用API函数实现这一点,其中两种方法是和

#include <windows.h>
#include <iostream>

int main() {

  SYSTEMTIME systmDateTime = {};
  ::GetLocalTime(&systmDateTime);

  wchar_t wszDate[64] = {};
  int const result = ::GetDateFormatW(
    LOCALE_USER_DEFAULT, DATE_SHORTDATE,
    &systmDateTime, 0, wszDate, _countof(wszDate));

  if (result) {
    std::wcout << wszDate;
  }
}
我想提供一些例子,但恐怕目前手头没有Win32编译器。希望上述文档中的示例足够了。

#包括
#include <windows.h>
#include <iostream>

int main() {

  SYSTEMTIME systmDateTime = {};
  ::GetLocalTime(&systmDateTime);

  wchar_t wszDate[64] = {};
  int const result = ::GetDateFormatW(
    LOCALE_USER_DEFAULT, DATE_SHORTDATE,
    &systmDateTime, 0, wszDate, _countof(wszDate));

  if (result) {
    std::wcout << wszDate;
  }
}
#包括 int main(){ SYSTEMTIME SystemDateTime={}; ::GetLocalTime(&systmDateTime); wchar_t wszDate[64]={}; int const result=::GetDateFormatW( 语言环境\u用户\u默认值,日期\u短日期, &SystemDateTime,0,wszDate,_countof(wszDate)); 如果(结果){ 标准::wcout
#包括
#包括
int main(){
SYSTEMTIME SystemDateTime={};
::GetLocalTime(&systmDateTime);
wchar_t wszDate[64]={};
int const result=::GetDateFormatW(
语言环境\u用户\u默认值,日期\u短日期,
&SystemDateTime,0,wszDate,_countof(wszDate));
如果(结果){
std::wcout阅读;GetLocalTime可能是您的朋友。还有标准的C时间函数time和strftime

作为将来的参考,在C程序中,调用外部实用程序并捕获其标准输出几乎总是错误的答案。

请阅读;GetLocalTime可能是您的朋友。还有标准的C时间函数time和strftime


作为将来的参考,在C程序中,调用外部实用程序并捕获其标准输出几乎总是错误的答案。

谢谢您的指针

我使用了这个,它达到了我的目的:

#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>
    int main()

    {  

        char tmpbuf[128];

        time_t ltime;

        struct tm *today;

        _strdate( tmpbuf );
        printf("\n before formatting date is %s",tmpbuf);  

        time(&ltime);
        today = localtime( &ltime );

        strftime(tmpbuf,128,"%d-%m-%y",today);
        printf( "\nafter formatting date is %s\n", tmpbuf );

    }
#包括
#包括
#包括
#包括
#包括
int main()
{  
char-tmpbuf[128];
时间;
struct tm*今日;
_标准剂量(tmpbuf);
printf(“\n格式化日期前为%s”,tmpbuf);
时间(<ime);
今天=本地时间(<ime);
标准时间(tmpbuf,128,“%d-%m-%y”,今天);
printf(“\n格式化日期后为%s\n”,tmpbuf);
}

-感谢你的指点

我使用了这个,它达到了我的目的:

#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>
    int main()

    {  

        char tmpbuf[128];

        time_t ltime;

        struct tm *today;

        _strdate( tmpbuf );
        printf("\n before formatting date is %s",tmpbuf);  

        time(&ltime);
        today = localtime( &ltime );

        strftime(tmpbuf,128,"%d-%m-%y",today);
        printf( "\nafter formatting date is %s\n", tmpbuf );

    }
#包括
#包括
#包括
#包括
#包括
int main()
{  
char-tmpbuf[128];
时间;
struct tm*今日;
_标准剂量(tmpbuf);
printf(“\n格式化日期前为%s”,tmpbuf);
时间(<ime);
今天=本地时间(<ime);
标准时间(tmpbuf,128,“%d-%m-%y”,今天);
printf(“\n格式化日期后为%s\n”,tmpbuf);
}
-广告