Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

date as string in other languages

0 views
Skip to first unread message

Fieger Michael

unread,
Jul 18, 2001, 10:32:14 AM7/18/01
to
Hi Everybody!

Is it possible to get a date as a string in other languages than english?

For Example:
The command strftime can give me a string like this: 'Wednesday, 18.07.01'
But I would need the weekday (and month) in the language that the system
(Windows) is set up.
So it should be 'Mittwoch, 18.07.01' on a german Windows.
I would need a solution that also works with other languages (German,
Afrikaans, Chinese,...)

Please help me if you can!

Mike


Jonesy

unread,
Jul 18, 2001, 3:29:48 PM7/18/01
to
Depending on the compiler you are using, there are different options. I use
BCC 3.1 and therefore use a 3rd party library "Winsys." It has a bunch of
date/time functions that will allow you program to display dates and times
based on the machine settings and user selected masks.

I am not sure what is available for the newer compilers.

Craig...

"Fieger Michael" <michael...@isagmbh.at> wrote in message
news:3b559dff_1@dnews...

Greg Chicares

unread,
Jul 18, 2001, 6:25:15 PM7/18/01
to
Fieger Michael wrote:
>
> Is it possible to get a date as a string in other languages than english?
>
> For Example:
> The command strftime can give me a string like this: 'Wednesday, 18.07.01'
> But I would need the weekday (and month) in the language that the system
> (Windows) is set up.
> So it should be 'Mittwoch, 18.07.01' on a german Windows.
> I would need a solution that also works with other languages (German,
> Afrikaans, Chinese,...)

Look into locales; if bc++ doesn't support them, try something like
this (with trivial changes to make it compile with pre-standard bc++).
I think anyone outside the US can read this already, and we'll get
there eventually too.

#include <cassert>
#include <cstddef>
#include <ctime>
#include <string>

std::string datestamp() // ISO8601 date and time
{
std::size_t const len = sizeof "CCYY-MM-DDTHH:MM:SSZ" / sizeof(char);
std::time_t t = std::time(0);
std::tm* gmt = std::gmtime(&t);
char s[len];
std::size_t rc = std::strftime(s, len, "%Y-%m-%dT%H:%M:%SZ", gmt);
assert(0 != rc);
return &s[0];
}

#include <iostream>

int main()
{
std::cout << datestamp() << '\n';
}

If you want a windows-specific solution, try the winapi group.

Barmak Shemirani

unread,
Jul 18, 2001, 7:06:27 PM7/18/01
to
In windows you can get the month name and weekday name.
char buf[101];
LCID lcid=GetThreadLocale();
GetLocaleInfo(lcid, LOCALE_SMONTHNAME1, buf, 100);
...
GetLocaleInfo(lcid, LOCALE_SMONTHNAME12, buf, 100);

GetLocaleInfo(lcid, LOCALE_SDAYNAME1, buf, 100);
...
GetLocaleInfo(lcid, LOCALE_SDAYNAME7, buf, 100);

I don't know about Chinese and other unicode.

Regards,
Barmak

Fieger Michael

unread,
Jul 19, 2001, 11:21:59 AM7/19/01
to
Thank you!

This was the solution to my problem. Works also well with Chinese!

Mike


0 new messages