C++如何使用时间函数(1)
来源:互联网 发布:风险评估算法 编辑:程序博客网 时间:2024/05/10 22:37
#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++如何使用时间函数(1)
- C++ 如何使用时间函数(2)--记忆游戏
- Android测试函数使用时间(动态代理)
- 如何有效使用时间
- 如何有效率地使用时间
- 使用时间函数查询
- 多线程使用时间函数
- 如何有效延长笔记本电池使用时间?
- C++模板类函数的使用以及如何使用时间作为文件名保存文件
- C++模板类函数的使用以及如何使用时间作为文件名保存文件
- 如何延长手机电池使用时间(from:http://blog.163.com/sz.sn/blog/static/6250252006710410300/)
- 如何查询表最后一次使用时间
- 如何破解Zend Studio的使用时间
- SQL语句使用时间和日期的函数
- 在C中来计算方法的使用时间
- WMI 获取硬盘信息(使用时间)
- Linux 2.6如何使用时间中断来完成进程调度
- jsp在循环中如何使用时间格式化拿到每个时间
- android常见问题集
- tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- 关于使用定义函数来实现对于数组c中的元素进行筛选最大值最小值,计算平均值等操作
- LVS-DR
- struts2拦截器interceptor
- C++如何使用时间函数(1)
- 人民币小写转大写(JavaScript实现)
- 关于模板实例化后的本身的连接问题
- AS 开发心得
- 《eclipse安装adt插件 提示的常见错误 - Cannot complete the install because one or more required items could not 》
- 网络通信模型(一)
- C++ 如何使用时间函数(2)--记忆游戏
- 人民币小写转大写(Java实现)
- android开发的问题集合