Home » U++ Library support » LineEdit, EditFields, DocEdit » Scan an timestamp
Scan an timestamp [message #27369] |
Wed, 14 July 2010 22:10  |
mubeta
Messages: 77 Registered: October 2006
|
Member |
|
|
Hi,
please, how I can scan this string of timestamp: "Wed, 14 Jul 2010 18:07:49 GMT", to a Time?
thanks.
|
|
|
Re: Scan an timestamp [message #27370 is a reply to message #27369] |
Wed, 14 July 2010 23:05  |
 |
koldo
Messages: 3432 Registered: August 2008
|
Senior Veteran |
|
|
mubeta wrote on Wed, 14 July 2010 22:10 | Hi,
please, how I can scan this string of timestamp: "Wed, 14 Jul 2010 18:07:49 GMT", to a Time?
thanks.
|
Hello Mubeta
If you remove the initial "Wed," you can use this:
// Like StrToDate but using Time
const char *StrToTime(struct Upp::Time& d, const char *s) {
s = StrToDate(d, s);
d.hour = d.minute = d.second = 0;
const char *fmt = "hms";
while(*fmt) {
while(*s && !IsDigit(*s))
s++;
int n;
if(IsDigit(*s)) {
char *q;
n = strtoul(s, &q, 10);
s = q;
} else
break;
switch(*fmt) {
case 'h':
if(n < 0 || n > 23)
return NULL;
d.hour = n;
break;
case 'm':
if(n < 0 || n > 59)
return NULL;
d.minute = n;
break;
case 's':
if(n < 0 || n > 59)
return NULL;
d.second = n;
break;
default:
NEVER();
}
fmt++;
}
return d.IsValid() ? s : NULL;
}
Time StrToTime(const char *s) {
Time ret;
StrToTime(ret, s);
return ret;
}
So
SetDateScan("dmy"); // Or set a language with the right date scan order
Time t = StrToTime("14 Jul 2010 18:07:49 GMT");
Best regards
IƱaki
|
|
|
Goto Forum:
Current Time: Fri Apr 25 21:31:55 CEST 2025
Total time taken to generate the page: 0.00511 seconds
|