H
Herby
Hi I have a string representation of a date in the following format:
'%Y-%m-%d'
As an example an actual value would be something like '2009-01-22'
I want to covert this to a time_t. I can only use the C functions for
this, so I have the following method that attempts this conversion:
Where mRawTime is time_t
void DateTime::SetDate( const String& date )
{
assert( date.empty() == false );
int yy=0, mm=0, dd=0;
struct tm when;
sscanf_s(date.c_str(), "%d-%d-%d", &yy, &mm, &dd );
when.tm_year = yy;
when.tm_mon = mm;
when.tm_mday = dd;
mRawTime = mktime(&when);
assert(mRawTime != -1 );
}
Trouble is the the mktime function always returns -1 so getting an
error on the conversion.
Can anyone see what is wrong?
Thanks in advance.
'%Y-%m-%d'
As an example an actual value would be something like '2009-01-22'
I want to covert this to a time_t. I can only use the C functions for
this, so I have the following method that attempts this conversion:
Where mRawTime is time_t
void DateTime::SetDate( const String& date )
{
assert( date.empty() == false );
int yy=0, mm=0, dd=0;
struct tm when;
sscanf_s(date.c_str(), "%d-%d-%d", &yy, &mm, &dd );
when.tm_year = yy;
when.tm_mon = mm;
when.tm_mday = dd;
mRawTime = mktime(&when);
assert(mRawTime != -1 );
}
Trouble is the the mktime function always returns -1 so getting an
error on the conversion.
Can anyone see what is wrong?
Thanks in advance.