【发布时间】:2017-01-25 18:59:24
【问题描述】:
我有这样的功能:
void ft_display_time(struct timespec ttime)
{
char *time_long;
time_long = ctime(&ttime.tv_sec);
if (time_long)
{
ft_printf("%.3s ", time_long + 4);
ft_printf("%.2s ", time_long + 8);
ft_printf("%.5s ", time_long + 11);
}
else
ft_putstr(" ");
}
我正在尝试获得像 ls -l 这样的输出。但ctime(const time_t *clock) 将返回一个英文字符串(因此月份显示为 "Dec" "Jan" "Aug" ...),而 ls -l 以主机语言格式(例如法语)输出月份。
例子:
./myprog --long file
-rw-r--r-- 1 lotolo staff 0 Sep 17 19:55 c
/bin/ls -l
-rw-r--r-- 1 lotolo staff 0 17 Set 19:55 c
我怎样才能获得宿主语言格式的输出?
例如,ttime 等于由stat(filename, &stat) 或lstat(filename, &stat) 返回的stat.st_atimespec 或stat.st_mtimespec
我知道我将不得不更改我的大部分ft_display_time() 功能,但我想知道是否有任何方法可以让ctime() 以正确的语言输出。
【问题讨论】:
-
在使用字符串显示例程之前,您是否尝试使用
setlocale(LC_ALL, NULL)设置区域设置? -
是的!我试过了,但没用……
标签: c linux io systems-programming ctime