on 11-10-2006 10:18 AM
Hi,
How to convert a java.util.date value to a string value?? Kindly help me with sample code.
Thanks,
Kalai.
easiest:
String StrDate;
StrDate = DateVar.toString();
esaier:
String StrDate = new String("");
String DD = new String("");
String MM = new String("");
String YY = new String("");
DD = new Integer(StrDate.getDay()).toString();
MM = new Integer(StrDate.getMonth()).toString();
YY = new Integer(StrDate.getYear()).toString();
StrDate = DD + "-" + MM + "-" + YY;
exist also a specific CLASS, DateFormat
http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormat.html
examples:
http://javatechniques.com/public/java/docs/basics/dateformat-examples.html
*Please reward helpfull answer.
Message was edited by:
Roberto Tagliento
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Perhaps a more straightforward approach than the "easier" is to use the standard formatting introduced in JDK 1.5
String strDate = String.format("%1$td - %1$tm - %1$tY .", myDate);
here %1$tm - means take the first argument, treat it as a time and from that extract the month and put it in the string.
HTH
Peter
User | Count |
---|---|
95 | |
11 | |
11 | |
10 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.