Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to write a date to a string

Posted on 2006-03-27
6
Medium Priority
?
235 Views
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);
            gmtFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
      }

and then later

writeChildElement(elt, "TimeStamp", gmtFormat.format(timeStamp));
mde.setTimeStamp(gmtFormat.parse(selectedElt.getText()));

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?
0
Comment
Question by:jjacksn
6 Comments
 
LVL 11

Assisted Solution

by:x4u
x4u earned 800 total points
ID: 16306238
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);
0
 
LVL 92

Accepted Solution

by:
objects earned 1200 total points
ID: 16306241
You can use SimpleDateFormat to format it in whatever formnat you want
0
 
LVL 92

Expert Comment

by:objects
ID: 16306258
> mde.setTimeStamp(gmtFormat.parse(selectedElt.getText()));

Why aren't you just using the original Date object instead of formatting and parsing back.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Expert Comment

by:Manikandan Thiagarajan
ID: 16306374
0
 
LVL 5

Author Comment

by:jjacksn
ID: 16307322
objects, not sure what you mean...?
0
 
LVL 92

Expert Comment

by:objects
ID: 16307335
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?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 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