how to write a date to a string

Posted on 2006-03-27
Last Modified: 2008-02-26
I'm trying to read/write a date to a string via the following method:

      private static DateFormat gmtFormat;                   
      static {
            gmtFormat = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);

and then later

writeChildElement(elt, "TimeStamp", gmtFormat.format(timeStamp));

But, it looks like the lower order numbers or removed from the value when I watch the Date object in the debugger.  Is there a string representation that is human readable that i can use?
Question by:jjacksn
    LVL 11

    Assisted Solution

    DateFormat.getDateInstance() does not format the time part of the date, you need to use DateFormat.getDateTimeInstance().

    gmtFormat = DateFormat.getDateTimeInstance(DateFormat.FULL,DateFormat.FULL, Locale.US);
    LVL 92

    Accepted Solution

    You can use SimpleDateFormat to format it in whatever formnat you want
    LVL 92

    Expert Comment

    > mde.setTimeStamp(gmtFormat.parse(selectedElt.getText()));

    Why aren't you just using the original Date object instead of formatting and parsing back.
    LVL 8

    Expert Comment

    LVL 5

    Author Comment

    objects, not sure what you mean...?
    LVL 92

    Expert Comment

    you're talkikng a date and formatting it as a string then back to a date again.
    Why can't you just use the original date instance instead of parsing the string?

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    This video teaches viewers about errors in exception handling.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now