chaitu chaitu
asked on
how to convert date to timestamp
i have a date which should be added by one day then add xtd time to that date and finally should be in Timestamp varaible.
int addoneday =1;
String xtd ="12:12"
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-y y");
Date date = (Date)formatter.parse("29- Jan-02");
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(c.DATE,addoneday);
Timestamp ts = new Timestamp(new SimpleDateFormat("ddMMMyy/ HH:mm").parse(c.geTime()). getTime()) ;
int addoneday =1;
String xtd ="12:12"
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-y
Date date = (Date)formatter.parse("29-
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(c.DATE,addoneday);
Timestamp ts = new Timestamp(new SimpleDateFormat("ddMMMyy/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
getting below exception
Exception in thread main
java.text.ParseException: Unparseable date: "Wed Jan 30 00:00:00 GMT+05:30 2002 12:12"
int xtd =1;
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-y y");
Date date = (Date)formatter.parse("29- Jan-02");
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(c.DATE,xtd);
String estime = c.getTime() + " 12:12";
Timestamp x= new Timestamp(new SimpleDateFormat("ddMMMyy HH:mm").parse(estime).getT ime());
System.out.println(x);
Exception in thread main
java.text.ParseException: Unparseable date: "Wed Jan 30 00:00:00 GMT+05:30 2002 12:12"
int xtd =1;
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-y
Date date = (Date)formatter.parse("29-
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(c.DATE,xtd);
String estime = c.getTime() + " 12:12";
Timestamp x= new Timestamp(new SimpleDateFormat("ddMMMyy HH:mm").parse(estime).getT
System.out.println(x);
Use the code i posted then
Timestamp ts = new Timestamp(cal.getTimeInMil lis());
Timestamp ts = new Timestamp(cal.getTimeInMil
ASKER
CEHJ
when i use this i am getting this format 2002-01-30 12:12:00.0;
how to this format 30-Jan-02 12:12???
Timestamp ts = new Timestamp(c1.getTimeInMill is());
System.out.println(ts);
when i use this i am getting this format 2002-01-30 12:12:00.0;
how to this format 30-Jan-02 12:12???
Timestamp ts = new Timestamp(c1.getTimeInMill
System.out.println(ts);
>>how to this format 30-Jan-02 12:12???
Use the format
dd-MMM-yy HH:mm
Use the format
dd-MMM-yy HH:mm
ASKER
Timestamp ts = new Timestamp(new SimpleDateFormat("dd-MMM-y y hh:mm").parse(formatter2.f ormat(c1.g etTime())) .getTime() );
You don't need to do any formatting/parsing if the source of the Date is the Calendar
:-)
> HH:mm").parse(c.geTime()).
should be
Timestamp ts = new Timestamp(c.getTimeInMilli