格式字符串为%x的strftime [英] strftime with format string %x
问题描述
大家好,
我想使用%x作为指令来获取区域设置特定日期
表示。但是,与此同时,我想知道通过程序解释它的输出格式
。有没有办法获得%x指令格式的
(它在不同的语言环境中有所不同)?例如,
默认(区域设置为C),%x给出%m /%d /%y。
谢谢
Param
Hi All,
I want to use %x as directive to get the locale specific date
representation. But, at the same time, i want to know the format of
the output for interpreting it through program. Is there a way to get
the format of the %x directive (it differs across locales)? For ex,
default (locale is C), %x gives like %m/%d/%y.
Thank you
Param
推荐答案
param写道:
param wrote:
大家好,
我想使用%x作为指令来获取区域设置特定日期
表示。但是,与此同时,我想知道通过程序解释它的输出格式
。有没有办法获得%x指令格式的
(它在不同的语言环境中有所不同)?例如,
默认(区域设置为C),%x给出%m /%d /%y。
Hi All,
I want to use %x as directive to get the locale specific date
representation. But, at the same time, i want to know the format of
the output for interpreting it through program. Is there a way to get
the format of the %x directive (it differs across locales)? For ex,
default (locale is C), %x gives like %m/%d/%y.
是的。对于C, locale%x说明符的格式为%m /%d /%y。要改变这一点,你需要调用带有LC_TIME的setlocale函数作为
第一个参数,并将所需的语言环境作为第二个参数。要找出当前语言环境类别的格式
,请将空指针作为setlocale的第二个
参数。参见C标准的第7.11节和第7.23.1节。
Yes. For the "C" locale the format for the %x specifier is %m/%d/%y. To
change this you need to call the setlocale function with LC_TIME as the
first argument and the desired locale as the second. To find out the format
of the category for the current locale pass a null pointer as the second
argument for setlocale. See sections 7.11 and 7.23.1 of the C Standard.
10月4日上午11:05,param< sparamesw ... @ gmail。编写:
On Oct 4, 11:05 am, param <sparamesw...@gmail.comwrote:
大家好,
我想用%x作为指令来获取特定于语言环境的日期
代表。但是,与此同时,我想知道通过程序解释它的输出格式
。有没有办法获得%x指令格式的
(它在不同的语言环境中有所不同)?例如,
默认(区域设置为C),%x给出%m /%d /%y。
谢谢
Param
Hi All,
I want to use %x as directive to get the locale specific date
representation. But, at the same time, i want to know the format of
the output for interpreting it through program. Is there a way to get
the format of the %x directive (it differs across locales)? For ex,
default (locale is C), %x gives like %m/%d/%y.
Thank you
Param
注意:请始终在查询正文中说明问题,而不是在标题中使用
。问题是关于strftime()的使用。
只需调用strftime两次 - 一次使用%x(可能你会向用户显示
) ,无论什么格式都是最方便的
供您使用。
-
Fred Kleinschmidt
>
param写道:
param wrote:
>
我想使用%x作为指令获取区域设置特定日期
表示。但是,与此同时,我想知道输出的格式
,以便通过程序解释它。是否有一种方法
来获取%x指令的格式(它在各种语言环境中有所不同)?
对于ex,默认(语言环境为C),%x给出类似%米/%d /%Y。
>
I want to use %x as directive to get the locale specific date
representation. But, at the same time, i want to know the format
of the output for interpreting it through program. Is there a way
to get the format of the %x directive (it differs across locales)?
For ex, default (locale is C), %x gives like %m/%d/%y.
>来自N869,适用于printf:
>From N869, for printf:
[#8]转换说明符及其含义是:
.... snip ...
o,u,x,X unsigned int参数被转换无符号
八进制(o),无符号十进制(u)或无符号
样式dddd中的十六进制表示法(x或X);
字母abcdef用于x转换,
字母ABCDEF用于X转换。精度
指定要显示的最小位数;如果
正在转换的值可以用
表示更少的数字,它会用前导零进行扩展。
默认精度为1.
转换零值的结果是零精度
没有字符。
对于strftime,再次来自N869:
7.23.3.5 strftime功能
概要
[#1]
#include< time.h>
size_t strftime(char * restrict s,
size_t maxsize,
const char *限制格式,
const struct tm * restrict timeptr);
.... snip ...
[# 3]每个转换说明符由适当的
字符替换,如下面的列表所述。
....剪辑...
%x由当地的适当日期替换
代表。 [均在7.23.1中指定]
这也表明你应该检查第7.23.1节。
-
Chuck F(cinefalconer at maineline dot net)
可用于咨询/临时嵌入式和系统。
< http://cbfalconer.home.att.net> ;
-
通过 http://www.teranews.com
[#8] The conversion specifiers and their meanings are:
.... snip ...
o,u,x,X The unsigned int argument is converted to unsigned
octal (o), unsigned decimal (u), or unsigned
hexadecimal notation (x or X) in the style dddd; the
letters abcdef are used for x conversion and the
letters ABCDEF for X conversion. The precision
specifies the minimum number of digits to appear; if
the value being converted can be represented in
fewer digits, it is expanded with leading zeros.
The default precision is 1. The result of
converting a zero value with a precision of zero is
no characters.
For strftime, again from N869:
7.23.3.5 The strftime function
Synopsis
[#1]
#include <time.h>
size_t strftime(char * restrict s,
size_t maxsize,
const char * restrict format,
const struct tm * restrict timeptr);
.... snip ...
[#3] Each conversion specifier is replaced by appropriate
characters as described in the following list. The
.... snip ...
%x is replaced by the locale''s appropriate date
representation. [all specified in 7.23.1]
Which also suggests you should examine section 7.23.1.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com
这篇关于格式字符串为%x的strftime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!