Click to See Complete Forum and Search --> : [RESOLVED] correctly formatting a date....


bryce4president
11-02-2007, 10:52 AM
our dates and times are stored as integer fields on the database. When I bring them in through an SQL resultSet I handle them with the following code...

Date ecldate = new SimpleDateFormat("yyyyMMddHHmmss").parse("00000000000000");
txtdate = ECL.getString("lodte");
txttime = ECL.getString("clentm");
if(txttime.length() < 6)
{
txttime = "0" + txttime;
}
txttimestamp = txtdate + txttime;
long inttxttimestamp = Long.parseLong(txttimestamp);
if(inttxttimestamp == 0)
{
txttimestamp = "20071201000000";
}
ecldate = new SimpleDateFormat("yyyyMMddHHmmss").parse(txttimestamp);


This works, and it formats the date, but I don't like the format its in. This is what it gives me...

Fri Oct 12 16:01:30 EDT 2007

I would like the format to be something like this...

October 12, 2007 4:01 PM

I can't seem to get my head around how this is done. I've tried to use a formatter and such, but I just don't understand it I guess...

Any help is appreciated.

bryce4president
11-02-2007, 02:12 PM
Good news. I figured it out thanks to this link....

http://www.biglist.com/lists/xsl-list/archives/199910/msg00087.html

I was able pull out the simpledateformat stuff and get it to work.

here is how I coded it...
First I initialize it, then I use it. I just inject the string into a table cell then.
Easy breezy, I hope this helps someone.

String ecldatetime = new SimpleDateFormat("M dd, yyyy K:mm a").format(new SimpleDateFormat("yyyyMMddHHmmss").parse("00000000000000", new ParsePosition(0)));

ecldatetime = new SimpleDateFormat("MMM dd, yyyy K:mm a").format(new SimpleDateFormat("yyyyMMddHHmmss").parse(ecltimestamp, new ParsePosition(0)));


Bryce