strftime
strftime,是一种计算机函数,strftime() 函数根据区域设置格式化本地时间/日期,函数的功能将时间格式化,或者说格式化一个时间字符串。
头文件:time.h
size_t
strftime
(
char
*strDest,
size_t
maxsize,
const
char
*format,
const
struct
tm
*timeptr
);
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include"time.h"
#include"stdio.h"
intmain( void )
{
struct tm * ptr;
time_t lt;
char str[80];
lt= time (NULL);
ptr= localtime (<);
strftime (str, sizeof (str), "Itisnow%I%p" ,ptr);
printf ( "%s\n" ,str);
return0;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include<stdio.h>
#include<time.h>
intmain( void )
{
structtm* newtime;
char tmpbuf[128];
time_t lt1;
time (<1);
newtime= localtime (<1);
strftime (tmpbuf,128, "Todayis%A,day%dof%Bintheyear%Y.\n" ,newtime);
printf ( "%s\n" ,tmpbuf);
return0;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include<stdio.h>
#include<time.h>
int main()
{
time_t rawtime;
struct tm * timeinfo;
char timE[80];
time (&rawtime);
timeinfo= localtime (&rawtime);
strftime (timE,80, "Data:\n%Y-%m-%d\nTime:\n%I:%M:%S\n" ,timeinfo);
printf ( "%s" ,timE);
return0;
}
|