Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

to get local Date...

Thread view: 
Bumsys@gmail.com - 18 Mar 2008 08:23 GMT
I want to get local Date from windows. this date depends on what
windows is installed(English, German).
For Example: English windows time: 3/18/08 9:21 AM
German windows time: 18.03.08 09:22

How can I get this Date?
Roedy Green - 18 Mar 2008 11:21 GMT
>How can I get this Date?

see http://mindprod.com/jgloss/calendar.html

You will use SimpleDateFormat
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Nigel Wade - 18 Mar 2008 12:57 GMT
> I want to get local Date from windows. this date depends on what
> windows is installed(English, German).
> For Example: English windows time: 3/18/08 9:21 AM

That would be American format, we English prefer our dates in sequential order
rather than inside-out order.

> German windows time: 18.03.08 09:22
>
> How can I get this Date?

Use DateFormat and Local.

For example:

package tests;

import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;

public class FormatDate {
 public static void main(String[] args) {
   Locale american = new Locale("en", "US" );
   Locale german = new Locale("de", "DE");
       
   DateFormat americanFormat =
     DateFormat.getDateInstance(DateFormat.SHORT, american);
   DateFormat germanFormat =
     DateFormat.getDateInstance(DateFormat.SHORT, german);
       
   Date date = new Date();
       
   System.out.println(americanFormat.format(date));
   System.out.println(germanFormat.format(date));
 }
}

will produce the following output:
3/18/08
18.03.08

As for getting the time, I'll leave that as an exercise for the student...

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Bumsys@gmail.com - 18 Mar 2008 13:28 GMT
but i need also to have the time 09:22 not only date  18.03.08...
Lew - 18 Mar 2008 13:36 GMT
> but i need also to have the time 09:22 not only date  18.03.08...

Read the docs.  You have to be able to learn some things on your own - in this
case it's like asking for directions to the gas station that's a quarter mile
from the off-ramp after Nigel told you which exit to take off the highway.

He told you he left it "as an exercise for the student" - you don't want to
miss out on your exercise.  It's good for your health.

Signature

Lew

Bumsys@gmail.com - 18 Mar 2008 14:06 GMT
Roedy Green - 18 Mar 2008 16:51 GMT
>but i need also to have the time 09:22 not only date  18.03.08...

I already gave the answer to you.  You ignored what I gave you
already. Presumably you believed it had no value without even looking
at it.

When someone ignores a gift you spent days preparing, you tend to
avoid helping that person again.

See http://mindprod.com/jgloss/newsgroups.html
for hints on getting the maximum benefit from your questions.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Lew - 18 Mar 2008 13:34 GMT
>> I want to get local Date from windows. this date depends on what
>> windows is installed(English, German).
[quoted text clipped - 8 lines]
>
> Use DateFormat and Local.
                     ^^^^^
Locale, as in java.util.Locale.

Actually /getting/ the date from Windows does not involve formats - you're
reading an integral quantity from the system clock.  Time zones remain an
issue, but string formats are completely irrelevant.

/Displaying/ the date according to locale, or parsing a string that represents
a date, use the advice Nigel and others gave.

Signature

Lew

Nigel Wade - 18 Mar 2008 15:54 GMT
>>> I want to get local Date from windows. this date depends on what
>>> windows is installed(English, German).
[quoted text clipped - 10 lines]
>                       ^^^^^
> Locale, as in java.util.Locale.

"Ee, bah gum!", as they would say in my locale.

At least it was correct in the example code...

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Roedy Green - 18 Mar 2008 16:43 GMT
>That would be American format, we English prefer our dates in sequential order
>rather than inside-out order.

ISO dates are yyyy-mm-dd

Given that almost everything you write now adays could potentially be
read by people anywhere in the world, it seems to me we would should
be avoiding national date formats and using ISO.  

National dates in isolation are ambiguous. They might be dd-mm or
mm-dd.  ISO date format thankfully is still unambiguous.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Nigel Wade - 18 Mar 2008 16:56 GMT
>>That would be American format, we English prefer our dates in sequential order
>>rather than inside-out order.
[quoted text clipped - 6 lines]
>
> National dates in isolation are ambiguous.

Indeed. Trying to decide exactly what is meant by a date of the format 2/3/2008
is a big problem. Good software will use the locale, bad software will hardcode
the programmer's idea of the locale. But which did any particular piece of
software actually use?

One of the worst culprits I have to deal with is Veritas NetBackup, a rather
expensive enterprise backup system. Because it's American software all dates
are output in US format, even though the GUI interface is written in Java. It
must have taken them more work to hardcode the output format specifiers to US
than it would have done to use a Locale and its date formatters.

Signature

Nigel Wade, System Administrator, Space Plasma Physics Group,
           University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Dr J R Stockton - 19 Mar 2008 19:22 GMT
>Indeed. Trying to decide exactly what is meant by a date of the format 2/3/2008
>is a big problem. Good software will use the locale, bad software will hardcode
>the programmer's idea of the locale.

Good software will use either the locale or the ISO form for human I/O.

But, for communicating with other systems elsewhere, good software will
use a fixed, agreed, and preferably ISO format.

Nowadays, too, a single locale  may not suit a given user (Locale was
probably introduced on the basis that people all use the same system
mm/dd/yy hh:mm am, except for foreigners).

But, hereabouts, while almost everyone uses GMT in winter and BST in
summer, hence the "proper" chronological locale, a very large proportion
would probably prefer Korean locale otherwise.

Signature

(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk  BP7, Delphi 3 & 2006.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
<URL:http://www.borland.com/newsgroups/guide.html> news:borland.* Guidelines

Dr J R Stockton - 19 Mar 2008 19:13 GMT
In comp.lang.java.programmer message <0jovt3hlq7vmvt8otii5gelhag8u8hiefu
@4ax.com>, Tue, 18 Mar 2008 15:43:04, Roedy Green <see_website@mindprod.
com.invalid> posted:

>National dates in isolation are ambiguous. They might be dd-mm or
>mm-dd.  ISO date format thankfully is still unambiguous.

If one knows the string to be an ISO date, it is unambiguous.  Extended
format - yyyy-mm-dd - could be an arithmetic expression.  And it should
not be assumed that a date such as 20080305 is ISO Basic format (try
Google for that string).

Signature

(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk  Turnpike v6.05  MIME.
Web  <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

Dr J R Stockton - 20 Mar 2008 22:56 GMT
In comp.lang.java.programmer message <WgORJNPnfV4HFwWY@invalid.uk.co.dem
on.merlyn.invalid>, Wed, 19 Mar 2008 18:13:59, Dr J R Stockton
<jrs@merlyn.demon.co.uk> posted:
>In comp.lang.java.programmer message <0jovt3hlq7vmvt8otii5gelhag8u8hiefu
>@4ax.com>, Tue, 18 Mar 2008 15:43:04, Roedy Green <see_website@mindprod.
[quoted text clipped - 7 lines]
>not be assumed that a date such as 20080305 is ISO Basic format (try
>Google for that string).

Oops : I meant to write "for YYYYDDMM".

Signature

(c) John Stockton, nr London, UK.    ?@merlyn.demon.co.uk     Turnpike v6.05.
Web  <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.