473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dates, locales

I was surprised to discover that the following code emits the formatted
date string uisng the default locale (C/POSIX), and I am required to
uncomment the line that imbues the "ja_JP" locale into cout in order to
get Japanese-language output.

I am surprised by this, because I thought that the text ought to vary
on the locale from which I obtained the time_put facet, rather than on
the locale used by the output stream. Is G++ (v4.03) right, or is it
something implementation-defined? Does this follow the spirit of the
Standards intentions? Is there something to quote from the Standard to
enlighten me, or other resources to help?

Also, is this method even the preferred way to print a date to an
output stream?

-----
#include <locale>
#include <iostream>
#include <ctime>
#include <utility>

#define CHAR_ARRAY_STR_END(a) ((a) + (sizeof(a)) - 1)

using namespace std;

int main(void)
{
const char format[] = "%c\n";
const char *format_end = CHAR_ARRAY_STR_END(format);
time_t secs = time(0);
std::tm *t = localtime(&secs);

const locale loc("ja_JP.utf8");
// cout.imbue(loc);
const time_put<char>& tp = use_facet<time_put<char(loc);
tp.put(cout, cout, ' ', t, format, format_end);
cout << flush;
}
-----

Nov 28 '06 #1
0 864

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

Similar topics

2
by: Adrian Parker | last post by:
I have a server app which is sent a date in the local format of the client machine. I've no control over the client app at all, so have to code at the server end to cope with any problems. The...
2
by: garykpdx | last post by:
Is there some sort of tutorial on locales or the locale module? I can't seem to find a list showing all possible locales. I made 'en' work alright, but when I tried 'de' or 'de_DE' or 'es_ES',...
2
by: Kenneth | last post by:
Hi, I have installed VS.NET 2000 on an english version of windows 2000 professional and in control panel I've chosen Regional Options and on the general Tab I have Swedish in Your...
0
by: news | last post by:
This had me stumped for ages yesterday, and since I solved it and can't find much reference to the problem, I thought I'd post here. I have various vbscript ASP pages that take an ADO recordset...
3
by: Phoe6 | last post by:
I would like to parse RFC 1123 date format and compare two dates. I find that datetime module does not specifically confirms to any RFC. Any suggestions as how I can handle the RFC 1123 date...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.