C++如何使用时间函数(1)
2012-11-24 14:31
453 查看
#include <stdio.h>
#include <time.h>
int main(void)
{
const char *Day[7] = {
"Sunday" , "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
};
const char *Month[12] = {
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
};
const char *Suffix[4] = { "st", "nd", "rd", "th" };
enum sufindex { st, nd, rd, th } sufsel = th; /* Suffix selector */
struct tm *OurT = NULL; /* Pointer for the time structure */
time_t Tval = 0; /* Calendar time */
Tval = time(NULL); /* Get calendar time */
OurT = localtime(&Tval); /* Generate time structure */
switch(OurT->tm_mday)
{
case 1: case 21: case 31:
sufsel= st;
break;
case 2: case 22:
sufsel= nd;
break;
case 3: case 23:
sufsel= rd;
break;
default:
sufsel= th;
break;
}
printf("Today is %s the %d%s %s %d", Day[OurT->tm_wday],
OurT->tm_mday, Suffix[sufsel], Month[OurT->tm_mon], 1900 + OurT->tm_year);
printf("\nThe time is %d : %d : %d",
OurT->tm_hour, OurT->tm_min, OurT->tm_sec );
return 0;
}
#include <time.h>
int main(void)
{
const char *Day[7] = {
"Sunday" , "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
};
const char *Month[12] = {
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
};
const char *Suffix[4] = { "st", "nd", "rd", "th" };
enum sufindex { st, nd, rd, th } sufsel = th; /* Suffix selector */
struct tm *OurT = NULL; /* Pointer for the time structure */
time_t Tval = 0; /* Calendar time */
Tval = time(NULL); /* Get calendar time */
OurT = localtime(&Tval); /* Generate time structure */
switch(OurT->tm_mday)
{
case 1: case 21: case 31:
sufsel= st;
break;
case 2: case 22:
sufsel= nd;
break;
case 3: case 23:
sufsel= rd;
break;
default:
sufsel= th;
break;
}
printf("Today is %s the %d%s %s %d", Day[OurT->tm_wday],
OurT->tm_mday, Suffix[sufsel], Month[OurT->tm_mon], 1900 + OurT->tm_year);
printf("\nThe time is %d : %d : %d",
OurT->tm_hour, OurT->tm_min, OurT->tm_sec );
return 0;
}
相关文章推荐
- C++ 如何使用时间函数(2)--记忆游戏
- 基于C/C++时间函数的使用详解
- C/C++时间函数的使用
- C/C++时间函数使用方法介绍(2)
- <C/C++>日期和时间的使用(time相关函数大全)
- c++如何使用c中的函数,为什么?
- C/C++时间函数的使用
- C/C++时间函数使用方法介绍(3)
- C/C++时间函数使用方法
- C/C++时间函数使用方法
- C/C++时间函数使用方法
- C/C++时间函数使用方法
- C/C++时间函数使用方法
- 详细介绍C/C++时间函数使用方法
- 在VC6.0中创建和使用静态链接库&amp;amp;&amp;amp;C如何调用C++ 成员函数
- 不使用C/C++字符串数据库函数,如何自行编写strcpy()函数?
- C++中时间相关函数的使用
- C++中,如何定义和使用指向成员函数的指针
- 如何使用c++的成员函数指针
- C/C++时间函数使用方法介绍