By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

strftime with format string %x

P: n/a
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

Oct 4 '07 #1
Share this Question
Share on Google+
12 Replies


P: n/a
param wrote:
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.
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.

Oct 4 '07 #2

P: n/a
On Oct 4, 11:05 am, param <sparamesw...@gmail.comwrote:
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
Note: Always state the question in the body of your inquiry, not in
the heading. The question is about the use of strftime().

Just call strftime twice - once with %x (presumably you will display
this to the user), and once with whatever format is most convenient
for you to work with.
--
Fred Kleinschmidt

Oct 4 '07 #3

P: n/a
param wrote:
>
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.
>From N869, for printf:
[#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

Oct 4 '07 #4

P: n/a

"CBFalconer" <cb********@yahoo.coma écrit dans le message de news:
47***************@yahoo.com...
param wrote:
>>
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.
>>From N869, for printf:

[#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.
Why do you keep quoting from an obsolete draft (10 years old) and what does
printf have to do with the OP's question?

--
Chqrlie.
Oct 4 '07 #5

P: n/a
Charlie Gordon wrote:
"CBFalconer" <cb********@yahoo.coma écrit:
>param wrote:
>>>
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.
>>>From N869, for printf:

[#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.

Why do you keep quoting from an obsolete draft (10 years old) and
what does printf have to do with the OP's question?
a) Because it is the only one available in text format.
b) Because I didn't even notice the reference to strftime until I
had already prepared the answer, and thus left that answer and
extended it. :-)

--
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

Oct 5 '07 #6

P: n/a
Charlie Gordon said:

[in response to a couple of quotes from N869 from Chuck]
Why do you keep quoting from an obsolete draft (10 years old)
Since the text was word-for-word identical with ISO/IEC 9899:1999, what
difference does it make where he got it from? If you're going to complain
about obsolete drafts, fine, but please do so only when it actually makes
a difference.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 5 '07 #7

P: n/a
On Oct 4, 11:27 pm, fred.l.kleinschm...@boeing.com wrote:
On Oct 4, 11:05 am, param <sparamesw...@gmail.comwrote:
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

Note: Always state the question in the body of your inquiry, not in
the heading. The question is about the use of strftime().

Just call strftime twice - once with %x (presumably you will display
this to the user), and once with whatever format is most convenient
for you to work with.
--
Fred Kleinschmidt

Hi

Thank you for your time.
Question was, If we use %x directive in strftime, it gives different
output in different locale and also it depends on the implementation
(differs across unix platforms).
Like,
locale ouput
en_US 10/05/07
ko 2007 Oct 10
Ja Oct 10 2007 (something similar)

I want to know the output format of %x directive for each locale
(through any interface/directive). I couldn't able to find it.

Thank you
Param

Oct 5 '07 #8

P: n/a
On Oct 4, 10:18 pm, param <sparamesw...@gmail.comwrote:
On Oct 4, 11:27 pm, fred.l.kleinschm...@boeing.com wrote:


On Oct 4, 11:05 am, param <sparamesw...@gmail.comwrote:
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
Note: Always state the question in the body of your inquiry, not in
the heading. The question is about the use of strftime().
Just call strftime twice - once with %x (presumably you will display
this to the user), and once with whatever format is most convenient
for you to work with.
--
Fred Kleinschmidt

Hi

Thank you for your time.
Question was, If we use %x directive in strftime, it gives different
output in different locale and also it depends on the implementation
(differs across unix platforms).
Like,
locale ouput
en_US 10/05/07
ko 2007 Oct 10
Ja Oct 10 2007 (something similar)

I want to know the output format of %x directive for each locale
(through any interface/directive). I couldn't able to find it.

Thank you
Param- Hide quoted text -

- Show quoted text -
The standard says that the %x format will produce an "appropriate
date representation for the locale", but does not specify what
"appropriate" should mean. So different implementations may
produce different results, as long as that rseult is "appropriate"
for the locale.

You don't say WHY you want this information, so it is very hard
for us to provide an answer. What is it that you are trying
to accomplish? Is it merely curiosity?
--
Fred L. Kleinschmidt
Oct 5 '07 #9

P: n/a
On Oct 5, 7:26 pm, fred.l.kleinschm...@boeing.com wrote:
On Oct 4, 10:18 pm, param <sparamesw...@gmail.comwrote:
On Oct 4, 11:27 pm, fred.l.kleinschm...@boeing.com wrote:
On Oct 4, 11:05 am, param <sparamesw...@gmail.comwrote:
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
Note: Always state the question in the body of your inquiry, not in
the heading. The question is about the use of strftime().
Just call strftime twice - once with %x (presumably you will display
this to the user), and once with whatever format is most convenient
for you to work with.
--
Fred Kleinschmidt
Hi
Thank you for your time.
Question was, If we use %x directive in strftime, it gives different
output in different locale and also it depends on the implementation
(differs across unix platforms).
Like,
locale ouput
en_US 10/05/07
ko 2007 Oct 10
Ja Oct 10 2007 (something similar)
I want to know the output format of %x directive for each locale
(through any interface/directive). I couldn't able to find it.
Thank you
Param- Hide quoted text -
- Show quoted text -

The standard says that the %x format will produce an "appropriate
date representation for the locale", but does not specify what
"appropriate" should mean. So different implementations may
produce different results, as long as that rseult is "appropriate"
for the locale.

You don't say WHY you want this information, so it is very hard
for us to provide an answer. What is it that you are trying
to accomplish? Is it merely curiosity?
--
Fred L. Kleinschmidt
The problem is, our existing library (third party) prints the log
information using %x
directive, we want to display the log information between dates (like
search facility between dates) in our application. Since the date
format differs across the locales. We couldn't able to interpret the
dates. We can achieve the requirement by running the 'date' command
with the option +%x for different locale and store it in the
application. But it is a static solution. If we find out a interface/
directive to give the format of the %x directive, it would be helpful
and a dynamic solution.

Thank you
Param

Oct 6 '07 #10

P: n/a
param <sp**********@gmail.comwrites:
The problem is, our existing library (third party) prints the log
information using %x
directive, we want to display the log information between dates (like
search facility between dates) in our application. Since the date
format differs across the locales. We couldn't able to interpret the
dates. We can achieve the requirement by running the 'date' command
with the option +%x for different locale and store it in the
application. But it is a static solution. If we find out a interface/
directive to give the format of the %x directive, it would be helpful
and a dynamic solution.
Set the LC_TIME locale to "C" when using the third-party library.

--
Best regards, _ _
.o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
Oct 6 '07 #11

P: n/a
param wrote:
On Oct 5, 7:26 pm, fred.l.kleinschm...@boeing.com wrote:
>On Oct 4, 10:18 pm, param <sparamesw...@gmail.comwrote:
>>On Oct 4, 11:27 pm, fred.l.kleinschm...@boeing.com wrote:
On Oct 4, 11:05 am, param <sparamesw...@gmail.comwrote:
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
Note: Always state the question in the body of your inquiry, not in
the heading. The question is about the use of strftime().
Just call strftime twice - once with %x (presumably you will display
this to the user), and once with whatever format is most convenient
for you to work with.
--
Fred Kleinschmidt
Hi
Thank you for your time.
Question was, If we use %x directive in strftime, it gives different
output in different locale and also it depends on the implementation
(differs across unix platforms).
Like,
locale ouput
en_US 10/05/07
ko 2007 Oct 10
Ja Oct 10 2007 (something similar)
I want to know the output format of %x directive for each locale
(through any interface/directive). I couldn't able to find it.
Thank you
Param- Hide quoted text -
- Show quoted text -
The standard says that the %x format will produce an "appropriate
date representation for the locale", but does not specify what
"appropriate" should mean. So different implementations may
produce different results, as long as that rseult is "appropriate"
for the locale.

You don't say WHY you want this information, so it is very hard
for us to provide an answer. What is it that you are trying
to accomplish? Is it merely curiosity?
--
Fred L. Kleinschmidt

The problem is, our existing library (third party) prints the log
information using %x
directive, we want to display the log information between dates (like
search facility between dates) in our application. Since the date
format differs across the locales. We couldn't able to interpret the
dates. We can achieve the requirement by running the 'date' command
with the option +%x for different locale and store it in the
application. But it is a static solution. If we find out a interface/
directive to give the format of the %x directive, it would be helpful
and a dynamic solution.

Thank you
Param
Instead of the '%x' macro, use simpler things. '%d/%m/%y' for example.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Oct 6 '07 #12

P: n/a

param wrote:

<snip>
The problem is, our existing library (third party) prints the log
information using %x directive, we want to display the log
information between dates (like search facility between dates)
in our application. Since the date format differs across the locales.
We couldn't able to interpret the dates. We can achieve the
requirement by running the 'date' command with the option +%x
for different locale and store it in the application. But it is a static
solution. If we find out a interface/directive to give the format of the
%x directive, it would be helpful and a dynamic solution.
If you call the setlocale function with LC_TIME and a null pointer as
the
first and second arguments respectively, a pointer to the string
associated
with the category, (here LC_TIME), for the current locale is returned.

How you use this to solve your problem is upto you. Personally I'd try
Michal Nazarewicz's suggestion.

Oct 6 '07 #13

This discussion thread is closed

Replies have been disabled for this discussion.