[DGD] ctime() bug or feature?

Par Winzell zell at skotos.net
Sun Feb 8 15:46:26 CET 2004


Michael McKiel wrote:
> 
> Now how this causes problems...is you can't split the ctime(time()) up via:
> explode(ctime(time()), " ") 
> 
> Wouldn't it be so much nicer if the date was:
> "Sun Feb 08 09:03:25 2004", not
> "Sun Feb  8 09:03:25 2004"
> 
> Buggy or an annoying feature? :)

Neither. It's a very standard format (either simply by virtue of the 
C/Unix standard, or laid down in some RFC as well -- not sure) and it 
was chosen for many good reasons. None of those reasons, however, had 
anything to do with explode(), which strikes me as rather perplexing a 
way to parse ctime(). This is precisely what sscanf() is for.

   sscanf(ctime(time()), "%s %s %d %d:%d:%d %d",
          dayname, monthname, day, hour, minute, second, year)

will -always- succeed and return 7, filling in all the variables with 
good values. I honestly don't understand how that space can possibly 
bother you. :)

Zell

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list