File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

urgent please help

 
john mattucci
Ranch Hand
Posts: 331
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read all the posts and I havent really found an
answer to my question I was wondering the easist way to change
a Timestamp to the format mm/dd/yy eg i get 2001-10-01-00-00-00.... from timestamp what is an easy way to convert this to
10/01/01
Thank u for your time
------------------
 
Adam Hardy
Ranch Hand
Posts: 567
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm not at my development pc so i haven't tested this but you said it's urgent, so try this: you can use all the java.util.Date methods because Timestamp extends Date.
Check out .toString()
http://java.sun.com/j2se/1.3/docs/api/java/util/Date.html#toString()
 
john mattucci
Ranch Hand
Posts: 331
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this gives me a long string with too much info eg the day of the
week. I want a string in the form 10/28/01 and is there an easy way to get this from a Timestamp
------------------
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about -
Timestamp t = ....
out.println(t.getMonth()+"/"+t.getDate()+"/"+t.getYear());
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about -
Timestamp t = ....
out.println(t.getMonth()+"/"+t.getDate()+"/"+t.getYear());
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by john mattucci:
this gives me a long string with too much info eg the day of the
week. I want a string in the form 10/28/01 and is there an easy way to get this from a Timestamp

How about -
Timestamp t = ....
out.println(t.getMonth()+"/"+t.getDate()+"/"+t.getYear());
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for the repeated posts.
i tried it thrice because it refused to submit the reply the first time and then the next time too....
 
Adam Hardy
Ranch Hand
Posts: 567
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how about

 
Toyin Sogeke
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can use the java.util.StringTokenizer class as follows:
String sDate = "2001-10-11 00:00:00";
StringTokenizer sToken =
new StringTokenizer(sDate," ");
String datePart = sToken.nextToken();
sToken = new StringTokenizer(datePart,"-");
String yyyy = sToken.nextToken();
String mm = sToken.nextToken();
String dd = sToken.nextToken();
String yy = yyyy.substring(2,3);
StringBuffer sBuf = new StringBuffer( mm );
sBuf.append( "/" );
sBuf.append( dd );
sBuf.append( "/" );
sBuf.append( yy );
String mmddyy = sBuf.toString();
System.out.println( "Date: " + mmddyy );
This should print: 10/11/01
Hope the above code helps.
Cheers
Originally posted by john mattucci:
I have read all the posts and I havent really found an
answer to my question I was wondering the easist way to change
a Timestamp to the format mm/dd/yy eg i get 2001-10-01-00-00-00.... from timestamp what is an easy way to convert this to
10/01/01
Thank u for your time

 
Shiv Sidhaarth
Ranch Hand
Posts: 119
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If u r reading data from Oracle, u can use
to_char(datefield,'mm/dd/yy') while selecting columns in SQL statement.
Sankar
 
Ali Hassaan
Ranch Hand
Posts: 103
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
easiest way is to use to_date(date,"mm/dd/yyyy") in your sql query if you ar using oracle else in sqlserver CONVERT(char(50), date)..
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic