我找到当前系统日期和时间的程序是
#include<stdio.h>
#include<time.h>
struct date{
int day,month,year;
};
main()
{
time_t t;
time(&t);
printf("Today's date and time is %s",ctime(&t));
}
我希望将这个当前日期存储到结构中请给我一个建议。
答案 0 :(得分:3)
标准库已经具有与您类似的结构:#container{
max-width: 400px;
overflow: hidden;
}
img{
width: 100%;
object-fit: contain;
}
<div id="container">
<img src="http://images.fonearena.com/blog/wp-content/uploads/2013/11/Lenovo-p780-camera-sample-10.jpg" alt="your_keyword"/>
<div>
中的struct tm
。
<time.h>
该库提供了 int tm_sec; /* seconds (0 - 60) */
int tm_min; /* minutes (0 - 59) */
int tm_hour; /* hours (0 - 23) */
int tm_mday; /* day of month (1 - 31) */
int tm_mon; /* month of year (0 - 11) */
int tm_year; /* year - 1900 */
int tm_wday; /* day of week (Sunday = 0) */
int tm_yday; /* day of year (0 - 365) */
int tm_isdst; /* is summer time in effect? */
char *tm_zone; /* abbreviation of timezone name */
long tm_gmtoff; /* offset from UTC in seconds */
类型的全局变量,其由函数localtime
(针对您的时区)和gmtime
(针对GMT时间)填充。
C11还指定struct tm
和localtime_s
,以避免与全局变量相关的问题,但我不知道它们的支持程度如何。 POSIX还指定了类似的gmtime_s
和gmtime_r
。