time(NULL) returning wrong month???



hello everyone,
i am really confused with some of the c++ time() fn results i get:
let me put you into perspective:

im writing a logging utility the log files created will contain 14byte
samples of certain values of interest. the last 4bytes of each sample
are its timestamp (timestamp of samples), that is the # of seconds
since the epoch.
so thats one 'date' (timestamp of samples) to consider.

the 2nd date is the log file attribute timestamp (attribute
timestamp). of when it is created - the value anyway that you see when
you do an ls -l of the file. this is of the least importane for me but
i just am refering to it in case you understand smth i do not.

last is the date string i use to create the filename with (filename
timestamp). explaining: since the data will be copied on a flash drive
from the ARM unit on which the log utility will be run and then copied
onto a computer, i decided i didn't want to have to deal with changing
file attributes so i hard coded the file creation date onto the
filename (since it is important).

now that we have the 3 dates a little about the system:
its an ARM based embedded system and is running debian linux
i have set its date (with date -s) and since the unit is located in
greece the timezone is EET (east european time).
having set the date as such, when i call (in total) 3 functions to get
the time or the date

the timestamp of the samples is returned by a driver that is written
in c (unlike everything else that is c++) and that uses the kernel
call do_gettimeofday().

FileTime GetTime () //FileTime is a typedef of unsigned long
//this function returns the time in seconds from the Epoch
{
time_t current_time;
current_time=time(NULL);
Time=((FileTime)current_time);
return (Time);
};

and

DateTime GetFDate()
{

time_t current_time;
current_time=time(NULL);
DatTim.day=localtime(&current_time)->tm_mday;
DatTim.month=localtime(&current_time)->tm_mon;
DatTim.year=localtime(&current_time)->tm_year+1900;
DatTim.LTime=GetFTime();

return (DatTim);
};

where

FTime GetFTime()
{
time_t current_time;
current_time=time(NULL);

FTim.hour=localtime(&current_time)->tm_hour;
FTim.minute=localtime(&current_time)->tm_min;
FTim.second=localtime(&current_time)->tm_sec;

return (FTim);
};

the DatTim.month returns to me (currently) february, instead of march!
(it generally returns 1 month before the current month). I use
GetFDate to write the filename date string. however the bash command
'date' returns the right date... so the attribute timestamp is
correct, but the filename timestamp is wrong... any ideas? could it be
some bug?

thank you for your help
nass

.



Relevant Pages

  • Re: Creating a file with timestamp
    ... > timestamp that there is no way for this (the filename) to actually be ... If you are creating a filename based on a timestamp, ... I have a shell script that chooses the lowest ... that you wouldn't be creating multiple files with the same ...
    (comp.os.linux.misc)
  • Re: POSIX equivalent to readlink utility ?
    ... filename is newer than a certain internally defined period. ... I was speaking to the algorithm posed by the ... vary, the timestamp is not ... So your script may be useful, but not for the reason of timestamps. ...
    (comp.unix.shell)
  • [ANN] called_from 0.1.0 released
    ... which gets filename and line number of caller. ... ## if cache data is older than template file's timestamp, ... $ ruby setup.rb config ...
    (comp.lang.ruby)
  • Re: time(NULL) returning wrong month???
    ... im writing a logging utility the log files created will contain 14byte ... are its timestamp, that is the # of seconds ... last is the date string i use to create the filename with (filename ...
    (comp.unix.programmer)
  • Re: file access permission?
    ... How about just simple database table, in which you track the locking? ... filename | Contains the filename that is being locked. ... last_action | Timestamp when locking user was active. ... Something similar for queue. ...
    (comp.lang.php)