[Java]: Changing Timestamp format
Link |
by blackspryte
on 2009-09-09 07:31:51
|
hi guys newbie here in the board. just thought if some java developers here could give me their 2 cents regarding this problem i have. i have a timestamp variable passed to a method and the format of the timestamp variable is defaulted to yyyy-mm-dd hh:mm:ss (default java format). the thing is i'm required to change the format to yyyymmddhhmmss and here's what i have in mind: protected Timestamp changeTSFormat(Timestamp ts){ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); Date dt = (Date)ts; String strDt = sdf.format(dt); ts = ts.valueOf(strDt); return ts; } but the problem is the method above still returns a timestamp with format yyyy-mm-dd hh:mm:ss. i tried debugging it and found out that when .valueOf() is called, it changes the format back to yyyy-mm-dd hh:mm:ss. now my question is: is it possible to change the format of timestamp to another format (e.g.yyyyMMddHHmmss) asides from the default one? and of course how :). thanks.. |