473,465 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

String.Format on Japanese Windows

Hi,

I want to create dates in the following format: dd-MMM-yyyy e.g. 13-
Mar-2007

But are seeing some problems when running on a Japanese Windows XP.
Regional settings are set to JP.

Currently I am doing this
DateTime dat = DateTime.Now;
return String.Format("{0:dd}-{0:MMM}-{0:yyyy}", date);

US Windows returns 27-Feb-2007
Japanese Windows return 27-2-2007

So I tried to come up with a solution to that fixes but could only
find half of the solution.
CultureInfo ci = new CultureInfo("en-US");
datestring = dat.ToString("G", ci);
Console.WriteLine("en-US : " + datestring.Remove(datestring.IndexOf('
')));

This works on both versions but changed the date format to mm/dd/yyyy

When I do this:
DateTime dt = DateTime.Parse(datestring);
Console.WriteLine(dt.ToString("dd-MMM-yyyy"));
I am back to where I started!

Any help is much appeciated...

Regards
Lars Schouw

Feb 27 '07 #1
1 6491
Thort answer .. This does the stunt..
return date.ToString("dd-MMM-yyyy", new CultureInfo("en-US"));

Long answer:

CultureInfo ci = new CultureInfo("en-US");
DateTime dtn = DateTime.Now;
string datestring = dtn.ToString("d", ci);
Console.WriteLine("en-US : " + datestring);
DateTime dt = DateTime.Parse(datestring);
Console.WriteLine(dt.ToString("dd-MMM-yyyy"));
// Japanese Windows
// en-US : 2/27/2007
// 27-2-2007

// US Windows
// en-US : 2/27/2007
// 27-Feb-2007

Console.WriteLine(dtn.ToString("dd-MMM-yyyy", ci));
Console.WriteLine(dt.ToString("dd-MMM-yyyy"), ci);
// Japanese Windows
// 27-Feb-2007
// 27-2-2007

// US Windows
// 27-Feb-2007
// 27-Feb-2007
On Feb 27, 4:04 pm, schou...@yahoo.com wrote:
Hi,

I want to create dates in the following format: dd-MMM-yyyy e.g. 13-
Mar-2007

But are seeing some problems when running on a Japanese Windows XP.
Regional settings are set to JP.

Currently I am doing this
DateTime dat = DateTime.Now;
return String.Format("{0:dd}-{0:MMM}-{0:yyyy}", date);

US Windows returns 27-Feb-2007
Japanese Windows return 27-2-2007

So I tried to come up with a solution to that fixes but could only
find half of the solution.
CultureInfo ci = new CultureInfo("en-US");
datestring = dat.ToString("G", ci);
Console.WriteLine("en-US : " + datestring.Remove(datestring.IndexOf('
')));

This works on both versions but changed the date format to mm/dd/yyyy

When I do this:
DateTime dt = DateTime.Parse(datestring);
Console.WriteLine(dt.ToString("dd-MMM-yyyy"));
I am back to where I started!

Any help is much appeciated...

Regards
Lars Schouw

Feb 27 '07 #2

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

Similar topics

3
by: Benoit Martin | last post by:
in my windows app, I have some japanese text that I load from a text file and display on a label. No matter what type of encoding I try to use on the text file, the text always comes up as a bunch...
6
by: DFB_NZ | last post by:
Hi. I have had problems compiling a simple program that uses wstring. So....I wrote a small application that reads using char, fgetc etc in a text file and writes it out to another text file....
1
by: jim figurski | last post by:
Hi, I have an American computer using windows XP. I recently bought a japanese game to help me learn japanese as I play. I installed the game sucessfully, but the letters are not displayed in...
4
by: Thorben | last post by:
Hello group, does anybody knows a way to add Japanese language to a western language based application? Our software is switch-able between English and France. Now I got the job to add...
2
by: Ajit | last post by:
Is it possible to have a web service name in localized string. Let's say, can I have a web service developed in C# having class name in Japanese? I am trying to build a web service as follows ...
11
by: prats | last post by:
I want to write a GUI application in PYTHON using QT. This application is supposed to take in Japanese characters. I am using PyQt as the wrapper for using QT from python. I am able to take input...
1
by: tony.pahl | last post by:
We are converting a data warehouse to a Unicode database to get ready for multilingual support. If we will have 95% of our data in English as we currently do, and less than 5% in other foreign...
14
by: rohitpatel9999 | last post by:
Hi While developing any software, developer need to think about it's possible enhancement for international usage and considering UNICODE. I have read many nice articles/items in advanced C++...
10
by: John Brown | last post by:
Hi there, Does anyone know how to go about reading/writing a type to a file in a language (culture) independent way. For instance, let's say you're dealing with the native "System.Drawing.Size"...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...
1
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.