views:

70

answers:

2

What C function should I call to obtain a formatted date and time for the locale where the program is being executed?

I'm asking this question because I have run into a problem using the ClamAV daemon API. The VERSION command returns the date and time of the latest virus definitions, but the code uses a call to ctime to format it. As far as I can tell ctime does not format the datetime according to the current locale and uses the English abbreviations for days of the week and the month in the returned string. This causes problems as my Java program which uses the ClamAV API does respect the current locale and thus expects the day of the week and month name to have the local abbreviations.

The datetime format would need to be in the same format as that produced by ctime:

Www Mmm dd hh:mm:ss yyyy

Where Www is the weekday, Mmm the month in letters, dd the day of the month, hh:mm:ss the time, and yyyy the year.

I could rewrite the Java program to always assume English dates but I'd be happier to submit a patch to ClamAV as it seems like a bug on their side to me.

A: 

strftime

Doug Currie
+4  A: 

strftime("%c", ... should give you the preferred date and time representation for the current locale. Or (still with strftime) you can emulate ctime's format but with %b for current-locale month abbreviation, %a for current-locale weekday abbreviation, and so on.

Alex Martelli