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 / October 2006

Tip: Looking for answers? Try searching our database.

Get Time in MEDIUM format

Thread view: 
Vera - 09 Oct 2006 22:00 GMT
This code outputs the date and the time that an event occurs, but how
do I tell it to only output the time in MEDIUM format? I know this is
easy but I just don't see how to do it :(

    /** Method to Get Time of an Event */
    public static String getTimeOfEvent()
    {
        GregorianCalendar calendar = new GregorianCalendar();
        DateFormat formatter =
DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
            DateFormat.MEDIUM, Locale.US);
        TimeZone timeZone = TimeZone.getTimeZone("CST");
        formatter.setTimeZone(timeZone);
        String outputTime = formatter.format(calendar.getTime());
        return outputTime;
    }

Thank you :)
Infra Dig - 10 Oct 2006 03:58 GMT
> This code outputs the date and the time that an event occurs, but how
> do I tell it to only output the time in MEDIUM format? I know this is
[quoted text clipped - 14 lines]
>
> Thank you :)

Your code produces...

   Oct 9, 2006 9:50:28 PM

...on my system.  That looks correct to me -- i.e., both date and time are
in MEDIUM format.

If I understand your question, you want to output the time only, like so...

   9:50:28 PM

If that's what you want to do, then change this...

DateFormat formatter =
   DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
       DateFormat.MEDIUM, Locale.US);

...to this...

DateFormat formatter =
 DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.US);


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.