获取系统时间的方法
来源:互联网 发布:阿里云3306端口 编辑:程序博客网 时间:2024/05/16 12:59
void GetTime_Case_1()
{
// #include <windows.h>
// #include <stdio.h>
//方案— :能精确到毫秒级并且使用简洁方便;
SYSTEMTIME Time; //获取系统时间类
CString TimeString; //转换
char cBuffer[100] = {0};
GetLocalTime(&Time); //获取本地时间
TimeString.Format(_T("%4d-%2d-%2d %2d:%2d:%2d") //格式化输出到CString
,Time.wYear
,Time.wMonth
,Time.wDay
,Time.wHour
,Time.wMinute
,Time.wSecond);
sprintf(cBuffer,"%4d-%2d-%2d %2d:%2d:%2d /n",//格式化输出到cBuffer
Time.wYear,
Time.wMonth,
Time.wDay,
Time.wHour,
Time.wMinute,
Time.wSecond);
}
void GetTime_Case_1()
{
// #include <time.h>
// #include <stdio.h>
//方案二 :仅使用C标准库;但是只能精确到秒级
time_t GetTime = time(0);
char cBuffer[64];
strftime( cBuffer, sizeof(cBuffer), "%Y/%m/%d %X %A 本?年?第?%j天?%z",localtime(&GetTime) );
/*
size_t strftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr);
根据格式字符串生成字符串。
struct tm *localtime(const time_t *timer);
取得当地时间,localtime获取的结果由结构tm返回
返回的字符串可以依下列的格式而定:
%a 星期几的缩写。Eg:Tue
%A 星期几的全名。 Eg: Tuesday
%b 月份名称的缩写。
%B 月份名称的全名。
%c 本地端日期时间较佳表示字符串。
%d 用数字表示本月的第几天 (范围为 00 至 31)。日期
%H 用 24 小时制数字表示小时数 (范围为 00 至 23)。
%I 用 12 小时制数字表示小时数 (范围为 01 至 12)。
%j 以数字表示当年度的第几天 (范围为 001 至 366)。
%m 月份的数字 (范围由 1 至 12)。
%M 分钟。s
%p 以 ''AM'' 或 ''PM'' 表示本地端时间。
%S 秒数。
%U 数字表示为本年度的第几周,第一个星期由第一个周日开始。
%W 数字表示为本年度的第几周,第一个星期由第一个周一开始。
%w 用数字表示本周的第几天 ( 0 为周日)。
%x 不含时间的日期表示法。
%X 不含日期的时间表示法。 Eg: 15:26:30
%y 二位数字表示年份 (范围由 00 至 99)。
%Y 完整的年份数字表示,即四位数。 Eg:2008
%Z(%z) 时区或名称缩写。Eg:中国标准时间
%% % 字符。
*/
}
- 获取系统时间的方法
- 获取系统时间方法
- c#获取系统时间的方法
- linux c 获取系统时间的方法
- linux下获取系统时间的方法
- MFC获取系统当前时间的方法
- linux下获取系统时间的方法
- c#获取系统时间的方法
- linux下获取系统时间的方法
- linux下获取系统时间的方法
- 获取系统当前时间的方法
- inux下获取系统时间的方法
- 获取系统日期时间的简单方法
- linux下获取系统时间的方法
- 获取系统时间的方法--linux
- linux下获取系统时间的方法
- MFC获取系统时间的几个方法
- 获取系统时间的四种方法
- ASP限制客户访问权限
- 《程序员》0904期封面报道精彩预告:技术编年史
- sqlserver数据库连接字符串全解
- C#16进制的Sting转成Int,加密解密
- linux2.6.14.1到S3C2410上
- 获取系统时间的方法
- Tomcat DBCP 连接池参数说明
- 解决多线程代码中的11个常见问题[详细/经典]
- 熟悉你
- Linux 2.4 内核的同步机制(1) (信号量)
- 2009-03-19读书记录:《大话设计模式》第四章——开放-封闭原则
- detours与增量链接
- WinXP下CHM无法打开如何处理
- Dojo中日期格式化处理