Simple Java Date Conversion
Having some troubles and can't find a quick answer.. Im trying to store a date within a string, and later fetch it to convert it back to a date. However when storing the date using
Solution 1:
You could use SimpleDateFormat with its methods parse() and format().
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss.SSS");
String tmp = sdf.format(newDate());
Datedate = sdf.parse(tmp);
Solution 2:
Do you need it to be a string? long is easier :)
do
long time=newDate().getTime();
Datedate=newDate(time);
then you dont' have to parse
Solution 3:
SimpleDateFormatformatter=newSimpleDateFormat("dd/MM/yyyy");
// to stringStringdateStr= formatter.format(newDate());
// to date Datedate= formatter.parse(dateStr);
Solution 4:
use SimpleDateFormat as shown below.
SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd");
//this will convertdateinto string.
String temp = formatter.format(currentDate.getTime());
//this will convert string intodate format.
Datedate=(Date)formatter.parse(temp);
Post a Comment for "Simple Java Date Conversion"