注册 登录
编程论坛 C++教室

我把 C# 的编程放到了 C++,我想获取一个时间,但是不知道要怎么去入手

t120653918 发布于 2014-07-18 11:44, 483 次点击
#include<stdio.h>
#include<time.h>
#include<string.h>
void main()
{
     time_t rawtime;
     struct tm * Age;time ( &rawtime );
     Age = localtime ( &rawtime );
     getAge();
    Student std1=new Student();
    std1.no="2013111338";
    std1.na="lili";
    std1.se="女";
    std1.da="1993,01,01";
}

class Student
{
    public string stdno;
    public string stdna;
    public string stdse;
    public string stdda;

    int getAge();
    {
        DaTatime nowTime=DaTatime.Now;
    return nowTime.Year-stdda.Year;
    }
}
2 回复
#2
rjsp2014-07-18 12:20
程序代码:
#include <cstdio>
#include <ctime>

int foo( const char* str )
{
    int year, mon=0, day=0, hour=0, min=0, sec=0;
    if( sscanf(str,"%d,%d,%d",&year,&mon,&day) != 3 )
        return -1;

    time_t raw = time( NULL );
    int cur_year = (localtime(&raw)->tm_year+1900);

    return cur_year - year;
}

int main()
{
    printf( "age = %d\n", foo("2014,01,01") );
    printf( "age = %d\n", foo("1993,01,01") );

    return 0;
}
#3
t1206539182014-07-20 15:12
回复 2 楼 rjsp
int cur_year = (localtime(&raw)->tm_year+1900);

这句不太理解,为什么会要指向tm_year+1900呢,加1900是做什么用的
1