Forums Register Login

Modifying the TimeStamp data type

+Pie Number of slices to send: Send
Hi,
I was wondering if anyone knew how to modify the timestamp data type so that it output like: DD MMM YYYY HH:NN:SS
Has anyone done this? I tried to modify Timestamp.java in the java.sql directory but its a bit messy. Basically when I output a table using select * from tablename I get the date in the usual timestamp format and it doesn't look as nice as the format i'd like.
Any ideas are welcome.
Suhail
+Pie Number of slices to send: Send
Timestamps are not used for formatting. Use the SimpleDateFormat class to make the timestamp appear as you want:
http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html
Jamie
+Pie Number of slices to send: Send
Yes, I agree but I am outputting from a database table using a preparedstatement such as select * from tablename. If the date is a string in the column then there are no problems and simpledateformat works but when the date column is of the type timestamp then simpledate format has no effect. The code I have is below:
PreparedStatement ps22 = connection.prepareStatement("SELECT Date, Balance FROM Purse");
rs1 = ps22.executeQuery();
while (rs1.next()){
try {
TimeZone gmt = TimeZone.getTimeZone("GMT+1");
GregorianCalendar in = new GregorianCalendar(gmt);
SimpleDateFormat sdf = new SimpleDateFormat( "dd MMM yyyy hh:mm:ss" );
sdf.setCalendar(in);
String theDate = sdf.format(in.getTime());
try {
Date date = sdf.parse(theDate);
in.setTime(date);
java.sql.Timestamp sDate = new java.sql.Timestamp(date.getTime());

int dep = 0;
String pname = "Lunar Telecoms Ltd";
String bal = rs1.getString("Balance");
PreparedStatement psi1 = connection.prepareStatement("INSERT INTO Account " +
"VALUES (?, ?, ?, ?, ?)");
psi1.setTimestamp(1,sDate);
psi1.setString(2,pname);
psi1.setInt(3,dep);
psi1.setString(4,s);
psi1.setString(5,bal);
psi1.executeUpdate();
psi1.close();
Any ideas why this outputs the date column as a timestamp and not like I wanted it (dd MMM yyyy hh:mm:ss) ???
Any help is much appreciated.
Suhail

Originally posted by Jamie Robertson:
Timestamps are not used for formatting. Use the SimpleDateFormat class to make the timestamp appear as you want:
http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html
Jamie


rubbery bacon. rubbery tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1221 times.
Similar Threads
Oracle Date and Time problem
Current date and time
Hibernate - how to modify value before Hibernate stores it?
bad Timestamp Exception
Oracle Pivot table
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 01:15:02.