C++4.3.2 中 getdate() 函数的替代方法是什么?

Whats the alternative to the getdate() function in C++4.3.2?

这在 Turbo C++ 中运行,但不适用于较新版本的 C++。还有其他替代方案吗?

#include<stdio.h>
#include<dos.h>

main()
{
   struct date d;
   getdate(&d);
   printf("Current system date is %d/%d/%d\n",d.da_day,d.da_mon,d.da_year);
   return 0;
}

getdate最直接的类比是time + localtime

#include <stdio.h>
#include <time.h>       /* time_t, struct tm, time, localtime */

int main ()
{
    time_t rawtime;
    time ( &rawtime );

    tm * const ptm = localtime ( &rawtime );

    printf("Current system date is %d/%d/%d\n",
             ptm->tm_day,ptm->_mon+1,ptm->tm_year+1900);

    return 0;
}

或者,要获得更 "C++" 风格的方法,请查找 std::chrono