Привет всем
Помогите, пожалуйста, "перефразировать" код из винды:
text
while(true)
{
time_t time = time();
tm* lptm = getlocaltime(&time);
...
}
Привет всем
Помогите, пожалуйста, "перефразировать" код из винды:
while(true)
{
time_t time = time();
tm* lptm = getlocaltime(&time);
...
}
DimonK, вы просто скажите, что хотите получить в итоге.
Пожалуйста:
while(true)
{
time_t time = time();
tm* lptm = localtime(&time);
...
}
Привет всем
while(true)
{
//time_t time = time();
time_t time;
time(&time); //Так по идее надо
tm* lptm = localtime(&time);
...
}
Если бы это работало...
В результате у меня какая-то левая дата и время :(
Возможно у Вас часы настроены не на локал-тайм, а на UTC. Тогда попробуйте так:
time_t time;
time(&time); //Так по идее надо
tm* lptm = gmtime(&time);
...
Понятие "левая дата и время" мне (нам) ни о чем не говорит. Если бы Вы сказали, время на Вашем компе _такое-то_, а прога возвращает _вот_это_, то было бы легче Вам помочь. А так приходится гадать -- "что там у вас в боку колет: может аппендицит, может царапина, а может резинка от трусов. Кто его знает, что там у Вас!"
The localtime() function converts the calendar time timep to broken-time representation, expressed rela‐
tive to the user's specified timezone. The function acts as if it called tzset(3) and sets the external
variables tzname with information about the current timezone, timezone with the difference between Coor‐
dinated Universal Time (UTC) and local standard time in seconds, and daylight to a nonzero value if day‐
light savings time rules apply during some part of the year. The return value points to a statically
allocated struct which might be overwritten by subsequent calls to any of the date and time functions.
The localtime_r() function does the same, but stores the data in a user-supplied struct. It need not set
tzname, timezone, and daylight.
не?