to get local Date...

Discussion in 'Java' started by Bumsys@gmail.com, Mar 18, 2008.

  1. Guest

    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?
    , Mar 18, 2008
    #1
    1. Advertising

  2. Roedy Green Guest

    Roedy Green, Mar 18, 2008
    #2
    1. Advertising

  3. Nigel Wade Guest

    wrote:

    > 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...

    --
    Nigel Wade, System Administrator, Space Plasma Physics Group,
    University of Leicester, Leicester, LE1 7RH, UK
    E-mail :
    Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
    Nigel Wade, Mar 18, 2008
    #3
  4. Guest

    but i need also to have the time 09:22 not only date 18.03.08...
    , Mar 18, 2008
    #4
  5. Lew Guest

    Nigel Wade wrote:
    > wrote:
    >
    >> 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.

    ^^^^^
    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.

    --
    Lew
    Lew, Mar 18, 2008
    #5
  6. Lew Guest

    wrote:
    > 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.

    --
    Lew
    Lew, Mar 18, 2008
    #6
  7. Guest

    thanks...
    , Mar 18, 2008
    #7
  8. Nigel Wade Guest

    Lew wrote:

    > Nigel Wade wrote:
    >> wrote:
    >>
    >>> 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.

    > ^^^^^
    > 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...

    --
    Nigel Wade, System Administrator, Space Plasma Physics Group,
    University of Leicester, Leicester, LE1 7RH, UK
    E-mail :
    Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
    Nigel Wade, Mar 18, 2008
    #8
  9. Roedy Green Guest

    On Tue, 18 Mar 2008 11:57:12 +0000, Nigel Wade <>
    wrote, quoted or indirectly quoted someone who said :

    >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.
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Mar 18, 2008
    #9
  10. Roedy Green Guest

    On Tue, 18 Mar 2008 05:28:49 -0700 (PDT), wrote,
    quoted or indirectly quoted someone who said :

    >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.
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Mar 18, 2008
    #10
  11. Nigel Wade Guest

    Roedy Green wrote:

    > On Tue, 18 Mar 2008 11:57:12 +0000, Nigel Wade <>
    > wrote, quoted or indirectly quoted someone who said :
    >
    >>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.


    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.

    --
    Nigel Wade, System Administrator, Space Plasma Physics Group,
    University of Leicester, Leicester, LE1 7RH, UK
    E-mail :
    Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
    Nigel Wade, Mar 18, 2008
    #11
  12. 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).

    --
    (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, Mar 19, 2008
    #12
  13. In comp.lang.java.programmer message <froonh$ang$>,
    Tue, 18 Mar 2008 15:56:33, Nigel Wade <> posted:

    >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.

    --
    (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, Mar 19, 2008
    #13
  14. In comp.lang.java.programmer message <
    on.merlyn.invalid>, Wed, 19 Mar 2008 18:13:59, Dr J R Stockton
    <> posted:
    >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).


    Oops : I meant to write "for YYYYDDMM".

    --
    (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.
    Dr J R Stockton, Mar 20, 2008
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    593
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,242
    Michael Borgwardt
    May 30, 2004
  3. Matt
    Replies:
    2
    Views:
    511
    Pete Becker
    Nov 8, 2003
  4. Matt
    Replies:
    3
    Views:
    718
    Richard Heathfield
    Nov 8, 2003
  5. Replies:
    8
    Views:
    779
    Boris
    May 1, 2007
Loading...

Share This Page