473,657 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strftime with format string %x

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
12 4468
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
On Oct 4, 11:05 am, param <sparamesw...@g mail.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
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

"CBFalconer " <cb********@yah oo.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
Charlie Gordon wrote:
"CBFalconer " <cb********@yah oo.coma écrit:
>param wrote:
>>>
I want to use %x as directive to get the locale specific date
representatio n. 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
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
On Oct 4, 11:27 pm, fred.l.kleinsch m...@boeing.com wrote:
On Oct 4, 11:05 am, param <sparamesw...@g mail.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
On Oct 4, 10:18 pm, param <sparamesw...@g mail.comwrote:
On Oct 4, 11:27 pm, fred.l.kleinsch m...@boeing.com wrote:


On Oct 4, 11:05 am, param <sparamesw...@g mail.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 "appropriat e
date representation for the locale", but does not specify what
"appropriat e" should mean. So different implementations may
produce different results, as long as that rseult is "appropriat e"
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
On Oct 5, 7:26 pm, fred.l.kleinsch m...@boeing.com wrote:
On Oct 4, 10:18 pm, param <sparamesw...@g mail.comwrote:
On Oct 4, 11:27 pm, fred.l.kleinsch m...@boeing.com wrote:
On Oct 4, 11:05 am, param <sparamesw...@g mail.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 "appropriat e
date representation for the locale", but does not specify what
"appropriat e" should mean. So different implementations may
produce different results, as long as that rseult is "appropriat e"
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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1500
by: kevininstructor | last post by:
The following was copied from a web site for learning formatting. Dim myInt As Integer = 100 Dim FormatPrice As String = String.Format("Price = |{0,10:c }|", myInt) Console.WriteLine(FormatPrice) The result shown is no number but the character c as in the format string. Is the format not valid in this context? Thanks for your assistance, Kevin
6
3390
by: Servé Lau | last post by:
suppose I want to use sscanf get the functionname from a function prototype. Is the following format string correct then? char funcname; char *p = "func(void)"; sscanf(p, "%s", funcname); // "%s"
6
2608
by: Donal McWeeney | last post by:
Hi, Is there a way to specify on the predefined format strings like P and N that you want displayed all the decimals in the number... for example 3 will display 3 2.1 will display 2.1 3.21 will display 3.21
2
1574
by: MM | last post by:
Hi, I have a param class containg these vars:- string key; // eg: "WN" object value; // eg: 1.2 string format; // eg "F2" and I output these to a StreamWriter using nc_file.Write("{0}{1:" + param.format + "}", param.key, param.value);
7
7658
by: Eddy Soeparmin | last post by:
Hi, I need to display a DateTime field in 'mm/dd/yyyy' in a DataGrid.. On myGrid1 - Properties - Columns - myColumn1 - Text format string: I tried to put 'mm/dd/yyyy' in there and it displays 'mm/dd/yyyy' in stead of '04/10/2001'. I know I didn't do it right. Please let me know what's the correct way to display a 'mm/dd/yyyy' format for a DateTime coulmn. Thanks.
4
6984
by: James | last post by:
vb.net 2003 i used console.writeline to output to screen. eg console.writeline ("test1 : " & vbtab & v_test1) console.writeline ("test2 : " & vbtab & v_test2) etc etc result becomes
3
12791
by: stathisgotsis | last post by:
Hello everyone, Trusting K&R2 i thought until recently that spaces are ignored in scanf's format string. Reading arguments to the contrary confused me a little. So i now ask: Is scanf("%d%d",...) different from scanf("%d %d",...) in the Standard's point of view? Thank you.
7
5473
by: Tony Girgenti | last post by:
Hello. Trying to develop VS2005, SP1 windows form VB program. When i try a statement like below and the data is "24.95", without the quotes of course, regPriceString equals "000000000025+" . regPriceString = String.Format("{0:000000000000+}", merchandiseDataRow.Item("RegPrice"))
7
9941
by: moondaddy | last post by:
I need to format a string to it always has 2 digits in it. I'm getting the month like this: DateTime.Now.Month.ToString() Right now since it's August, this returns a string of "8", however, I need to return a string of "08". Is there a format method what will automatically pad this for me? Thanks.
7
13647
by: Andrus | last post by:
How to create format string for decimal data type which shows blank for zero and default format otherwize ? I tried format string "f;f;#" but this shows f for nonzero numbers. Andrus. using System.Windows.Forms;
0
8411
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.