How do I display the current time *including milliseconds*?

Discussion in 'Java' started by Al Koch, Jun 25, 2005.

  1. Al Koch

    Al Koch Guest

    How do I display the current time *including milliseconds*?

    Hello,

    I need to display the current time including milliseconds. The following
    code:

    DateFormat dfDateTimeStartupThread =
    DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.getDef
    ault());
    String sDateTimeStartupThread = dfDateTimeStartupThread.format(new Date());
    System.out.println(sDateTimeStartupThread);

    results in output like:

    June 25, 2005 1:23:18 PM EST

    which is nicely formatteed but I cannot find any way to get the milliseconds
    to display.

    How can this be done?

    Thanks,
    Al Koch,
     
    Al Koch, Jun 25, 2005
    #1
    1. Advertising

  2. Al Koch wrote:
    > How do I display the current time *including milliseconds*?
    >


    Take a look at java.util.SimpleDateFormat.

    HTH,
    Ray

    --
    XML is the programmer's duct tape.
     
    Raymond DeCampo, Jun 25, 2005
    #2
    1. Advertising

  3. Al Koch

    Al Koch Guest

    Hi Ray,

    > Take a look at java.util.SimpleDateFormat.


    Thanks very much; that was exactly what I needed! (although it's actually
    java.text.SimpleDateFormat).

    Al,
     
    Al Koch, Jun 27, 2005
    #3
  4. Al Koch wrote:
    > Hi Ray,
    >
    >
    >>Take a look at java.util.SimpleDateFormat.

    >
    >
    > Thanks very much; that was exactly what I needed! (although it's actually
    > java.text.SimpleDateFormat).
    >


    Of course, I make that mistake every time...

    Ray

    --
    XML is the programmer's duct tape.
     
    Raymond DeCampo, Jun 27, 2005
    #4
  5. Al Koch

    Joly Makunga Guest

    Al Koch wrote:

    > How do I display the current time *including milliseconds*?
    >
    > Hello,
    >
    > I need to display the current time including milliseconds. The following
    > code:
    >
    > DateFormat dfDateTimeStartupThread =
    > DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.getDef
    > ault());
    > String sDateTimeStartupThread = dfDateTimeStartupThread.format(new Date());
    > System.out.println(sDateTimeStartupThread);
    >
    > results in output like:
    >
    > June 25, 2005 1:23:18 PM EST
    >
    > which is nicely formatteed but I cannot find any way to get the milliseconds
    > to display.
    >
    > How can this be done?
    >
    > Thanks,
    > Al Koch,
    >
    >
    >
    >
    >
    >

    i do it like that

    Date madate=new Date();

    int heure=madate.getHours();
    int minute=madate.getMinutes();
    int jour=madate.getDate();

    i don't know how to get millisecondes...

    jolyqr
     
    Joly Makunga, Jun 30, 2005
    #5
  6. Al Koch

    James Korman Guest

    On Thu, 30 Jun 2005 11:40:47 +0200, Joly Makunga
    <> wrote:

    >Al Koch wrote:
    >
    >> How do I display the current time *including milliseconds*?
    >>
    >> Hello,
    >>
    >> I need to display the current time including milliseconds. The following
    >> code:
    >>
    >> DateFormat dfDateTimeStartupThread =
    >> DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL,Locale.getDef
    >> ault());
    >> String sDateTimeStartupThread = dfDateTimeStartupThread.format(new Date());
    >> System.out.println(sDateTimeStartupThread);
    >>
    >> results in output like:
    >>
    >> June 25, 2005 1:23:18 PM EST
    >>
    >> which is nicely formatteed but I cannot find any way to get the milliseconds
    >> to display.
    >>
    >> How can this be done?
    >>
    >> Thanks,
    >> Al Koch,
    >>
    >>
    >>
    >>
    >>
    >>

    >i do it like that
    >
    >Date madate=new Date();
    >
    >int heure=madate.getHours();
    >int minute=madate.getMinutes();
    >int jour=madate.getDate();
    >
    >i don't know how to get millisecondes...
    >
    >jolyqr


    Look at the JavaDoc for SimpleDateFormat, specifically the "S"
    pattern character.

    Jim
     
    James Korman, Jul 2, 2005
    #6
    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. Michelle
    Replies:
    5
    Views:
    4,303
    Michelle
    Aug 17, 2004
  2. Replies:
    5
    Views:
    1,628
    Ben Bacarisse
    Nov 19, 2006
  3. Replies:
    3
    Views:
    2,055
    Steven D'Aprano
    Jul 25, 2009
  4. Replies:
    6
    Views:
    3,610
    John W. Krahn
    May 12, 2008
  5. laredotornado

    Getting current time in milliseconds

    laredotornado, Oct 20, 2009, in forum: Perl Misc
    Replies:
    8
    Views:
    523
    RedGrittyBrick
    Oct 22, 2009
Loading...

Share This Page