Article View: borland.public.jbuilder.java.language
Article #306Re: Newbie Date question (but trickier than it looks)
From: Gillmer J. Derge [TeamB]
Date: Tue, 04 Oct 2005 17:18
Date: Tue, 04 Oct 2005 17:18
86 lines
4717 bytes
4717 bytes
Hugh Jones wrote:
> The OS setting on the client, however, *can be* different from the
> server. When I first ran this the 3rd party API call fell over because
> the OS was set to 'yyyy-MM-dd'.
>
> I can make the routine work by going into control panel and making sure
> the Client OS has 'dd/MM/yyyy', but this strikes me as being inherently
> crappy.
This is interesting. You're talking about Windows, I presume. To the
best of my knowledge, none of the Java date classes are tied to the
Windows date format settings. They get their formats from somewhere else.
To verify this, I did some experiments. I created a Date object and
printed it 6 different ways (sample output is shown):
* date.toString()
date = Tue Oct 04 13:05:53 EDT 2005
* DateFormat.getInstance().format(date)
dateFormat[0].format = Oct 4, 2005
* DateFormat.getInstance(DateFormat.SHORT).format(date)
dateFormat[1].format = 10/4/05
* DateFormat.getInstance(DateFormat.MEDIUM).format(date)
dateFormat[2].format = Oct 4, 2005
* DateFormat.getInstance(DateFormat.LONG).format(date)
dateFormat[3].format = October 4, 2005
* DateFormat.getInstance(DateFormat.FULL).format(date)
dateFormat[4].format = Tuesday, October 4, 2005
None of these correspond to my own Windows date format setting of
MM/dd/yyyy.
So my conclusion is that this Documentum method you're calling is using
some other approach to get the date format. Maybe it uses a native
method to query the OS setting. Maybe it does something else. Either
way, the point is that without knowing what that method is doing, it's
hard to speculate as to how to force it to use a different format.
Also, since it does seem like the Documentum class is using the Windows
settings, I don't think Java is going to offer you a way of coercing the
settings unless you write some native code of your own. The Java locale
and date format settings do not interact with the OS.
> Ideally I want to make sure that anyone running this at a later date can
> run it without recourse to a README. I sort of assumed that something like
>
> ---
>
> applyTemporaryLocale();
> try {
> documentumThingy.import();
> } finally {
> restoreDefaultLocale();
> }
>
> ---
>
> would be a breeze, if only I could find the right methods. This is
> something I would regularly do in Delphi. (and yes, I know that is a bad
> attitude)
>
> It looks like this is not possible in java. Do you agree ?
Yes and no. On the one hand, that's exactly what the code I gave you
does. So from that point of view, I don't agree at all.
On the other hand, the problem is that setting the Locale in Java
doesn't set the Windows Control Panel locale, and it doesn't change the
Windows Control Panel date format settings. So while this is working to
change the Java date format settings (such as the ones I used above), it
isn't doing anything to help solve your actual problem. :-) So from
that point of view I do agree. For a purely Java solution, you might be
out of luck on this one.
Do you have any way of getting support from Documentum? This sounds to
me like it's their issue and like you can't possibly be the first person
in the world to have encountered this. I wonder if maybe there's a way
to configure their API with a specific date format. Something like
DocumentumUtil.setDateFormat("MM/dd/yyyy").
--
Gillmer J. Derge [TeamB]
Technical Details
Message-ID:
<4342b8f8@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!pd7cy2so!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<434142fe$1@newsgroups.borland.com> <43414798$1@newsgroups.borland.com> <434230c1@newsgroups.borland.com> <43428921$1@newsgroups.borland.com> <43429dbf$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,597975fc8535d7af X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Tue, 04 Oct 2005 13:18:52 -0400 From: "Gillmer J. Derge [TeamB]" <spam@gillmerderge.com> User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: Newbie Date question (but trickier than it looks) References: <434142fe$1@newsgroups.borland.com> <43414798$1@newsgroups.borland.com> <434230c1@newsgroups.borland.com> <43428921$1@newsgroups.borland.com> <43429dbf$1@newsgroups.borland.com> In-Reply-To: <43429dbf$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.149.56.207 Message-ID: <4342b8f8@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1128446200 24.149.56.207 (4 Oct 2005 10:16:40 -0700) Lines: 86 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!pd7cy2so!pd7cy1no!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail