How to trim timestamp from a Date value

Hi,

Iam retrieving Date values from database(mysql). When i display these dates in a jsp ,those r displaying like this

2007-01-01 00:00:00.0

Actually we dont want that timestamp at the end of the date.

How can i trim that time stamp from date value.

We r using Hibernate to interact with database.

pls give some suggestions regarding this

thanks

[397 byte] By [ramineni_01a] at [2007-11-27 11:56:19]
# 1

may be regex can help u .

Once u get date in String use following

String Date = Date.replaceAll("regex" ,"");

This regex will find all 00:00: at the end of string

AmitChalwade123456a at 2007-7-29 19:06:55 > top of Java-index,Java Essentials,Java Programming...
# 2

> Hi,

> Iam retrieving Date values from database(mysql).

> When i display these dates in a jsp ,those r

> displaying like this

>2007-01-01 00:00:00.0

>

> Actually we dont want that timestamp at the end

> of the date.

>How can i trim that time stamp from date value.

> We r using Hibernate to interact with database.

>

> pls give some suggestions regarding this

>

> thanks

By display, I assume you mean something like:

System.out.println(myDate)

or

System.out.println(myDate.toString()); // which is the same thing

Use SimpleDateFormat class to format the date anyway you like.

jbisha at 2007-7-29 19:06:55 > top of Java-index,Java Essentials,Java Programming...
# 3

DateFormat df = new SimpleDateFormat("MMM dd yyyy hh:mm a");

Date d1 = df.parse("July 09 2007 9:00 PM");

DateFormat df2 = DateFormat.getDateInstance(DateFormat.MEDIUM);

System.out.println("d1 = ["+df2.format(d1)+"]");

try that

mark07a at 2007-7-29 19:06:55 > top of Java-index,Java Essentials,Java Programming...
# 4

Hai mark,

Actually the format() of DateFormat class will return a String object,

but as per our requirementthe date variable should be of type java.util.Date

thanks for responding

ramineni_01a at 2007-7-29 19:06:55 > top of Java-index,Java Essentials,Java Programming...
# 5

Dates in java are just a long indicating millis since the epoch, jan 1, 1970 00:00:00. The display is just that, a display, in which you use the SimpleDateFormat to determine what the user sees. It has no other meaning, and you cannot construct a Date object that doesn't have a time.

~Tim

SomeoneElsea at 2007-7-29 19:06:55 > top of Java-index,Java Essentials,Java Programming...
# 6

Thanks for valuable info

AmitChalwade123456a at 2007-7-29 19:06:55 > top of Java-index,Java Essentials,Java Programming...
# 7

> Dates in java are just a long indicating millis since

> the epoch, jan 1, 1970 00:00:00.

Dates in Java take a variety of forms (java.sql.Date, java.util.Date, java.util.Calendar, java.sql.Timestamp, etc.). The java.util.Date is a class, not a long. Whether or not it's represented internally as a long shouldn't matter to the developer.

> you cannot construct a Date object that doesn't have a time.

One can create a Date with a time of 00:00:00.000, however, in case such a thing is necessary. Great point about the display.

~

yawmarka at 2007-7-29 19:06:55 > top of Java-index,Java Essentials,Java Programming...