time(NULL) returning wrong month???
- From: "nass" <athanasios.silis@xxxxxxxxx>
- Date: 23 Mar 2007 02:54:43 -0700
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(¤t_time)->tm_mday;
DatTim.month=localtime(¤t_time)->tm_mon;
DatTim.year=localtime(¤t_time)->tm_year+1900;
DatTim.LTime=GetFTime();
return (DatTim);
};
where
FTime GetFTime()
{
time_t current_time;
current_time=time(NULL);
FTim.hour=localtime(¤t_time)->tm_hour;
FTim.minute=localtime(¤t_time)->tm_min;
FTim.second=localtime(¤t_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
.
- Follow-Ups:
- Re: time(NULL) returning wrong month???
- From: Gordon Burditt
- Re: time(NULL) returning wrong month???
- From: Martin Vuille
- Re: time(NULL) returning wrong month???
- From: Rainer Weikusat
- Re: time(NULL) returning wrong month???
- From: nass
- Re: time(NULL) returning wrong month???
- Prev by Date: Raw disk access?
- Next by Date: Re: time(NULL) returning wrong month???
- Previous by thread: Raw disk access?
- Next by thread: Re: time(NULL) returning wrong month???
- Index(es):
Relevant Pages
|