LinuxForum.Fans
Тема

Таймер

Автор: DimonK 6 сообщений 1738 просмотров
#133787

Привет всем

Помогите, пожалуйста, "перефразировать" код из винды:

text

while(true)
{
time_t time = time();
tm* lptm = getlocaltime(&time);
...
}
#133788

DimonK, вы просто скажите, что хотите получить в итоге.

#133790

Пожалуйста:

text

while(true)
{
time_t time = time();
tm* lptm = localtime(&time);
...
}
#134861

Привет всем

text

while(true)
{
//time_t time = time();
time_t time;
time(&time); //Так по идее надо
tm* lptm = localtime(&time);
...
}

Если бы это работало...
В результате у меня какая-то левая дата и время :(

#134887

Возможно у Вас часы настроены не на локал-тайм, а на UTC. Тогда попробуйте так:

text

  time_t time;

time(&time); //Так по идее надо tm* lptm = gmtime(&time);

...

Понятие "левая дата и время" мне (нам) ни о чем не говорит. Если бы Вы сказали, время на Вашем компе _такое-то_, а прога возвращает _вот_это_, то было бы легче Вам помочь. А так приходится гадать -- "что там у вас в боку колет: может аппендицит, может царапина, а может резинка от трусов. Кто его знает, что там у Вас!"

#134919
man localtime написал:
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.

не?

Войдите или зарегистрируйтесь, чтобы ответить.