C++ 将日期的成员存储在不同的变量中
目前我正在运行以下代码C++ 将日期的成员存储在不同的变量中,c++,c,ubuntu,time,C++,C,Ubuntu,Time,目前我正在运行以下代码 int main() { while(1) { time_t current = time(NULL); cout << ctime(¤t)<< endl; } } intmain(){ 而(1) { 时间\u t当前=时间(空); cout如果您想有时间查找\uuuu TIMESTAMP\uuuu变量。它应该是这样的:12 Sat 1
int main() {
while(1)
{
time_t current = time(NULL);
cout << ctime(¤t)<< endl;
}
}
intmain(){
而(1)
{
时间\u t当前=时间(空);
cout如果您想有时间查找\uuuu TIMESTAMP\uuuu
变量。它应该是这样的:12 Sat 16 12:00:00您想要的函数是localtime
此函数获取时间的地址
并返回指向struct tm
的指针,该指针包含分解为年、月、日、小时、分钟和秒的日期和时间
从:
localtime()
函数将日历时间timep
转换为
分解的时间表示法,相对于用户的
指定的时区。该函数的作用就好像它调用了tzset(3)和
设置外部变量tzname
,其中包含有关当前
时区,时区之间的差异协调普遍
时间(UTC)和当地标准时间(以秒为单位),日光为
如果夏令时规则在某些时间段适用,则为非零值
年份。返回值指向静态分配的struct
这可能会被对任何日期和时间的后续调用覆盖
时间函数
struct tm
的定义如下:
struct tm {
int tm_sec; /* seconds */
int tm_min; /* minutes */
int tm_hour; /* hours */
int tm_mday; /* day of the month */
int tm_mon; /* month */
int tm_year; /* year */
int tm_wday; /* day of the week */
int tm_yday; /* day in the year */
int tm_isdst; /* daylight saving time */
};
给你试的样例代码…我想要一辆新车。最好是红色的。那么问题是什么?你遇到了什么特殊问题吗?如果你不知道从哪里开始,请读一本好的C++书籍。通过反复试验或通过互联网随机的片段学习C++是行不通的。
struct tm {
int tm_sec; /* seconds */
int tm_min; /* minutes */
int tm_hour; /* hours */
int tm_mday; /* day of the month */
int tm_mon; /* month */
int tm_year; /* year */
int tm_wday; /* day of the week */
int tm_yday; /* day in the year */
int tm_isdst; /* daylight saving time */
};