on 09-18-2007 4:48 AM
hi
i have function which returns string as current time in hh:mm:ss format
the code is like this
Date d3=new Date(System.currentTimeMillis());
int a=d3.getHours();
int b=d3.getMinutes();
int c=d3.getSeconds();
String v=a":"b":"c;
return v;
here insted of string i need to get current time in time with same hh:mm:ss format
can any body suggest me how to covert v(i.e string format time into time data type)
Regards,
vani
Hi
just try following one line of code to get what u want:
import java.sql.Time;
Time myTime = new Time(a, b, c);
(where a, b, c are hrs, min & sec respectively)
OR
simply derive time from Date (dont use a, b, c)
import java.sql.Date;
import java.sql.Time;
Date currDate = new Date(System.currentTimeMillis());
Time currTtime = new Time(currDate.getTime());
Regards
Deepak.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Date d3=new Date(System.currentTimeMillis());
TimeShift.formatTime(d3,"hh:mm:ss");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Date dt =sdf.parse(strFormatDate);
after getting dt
use
dt.getTime();
Regards
Abhijith YS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
chk it
http://www.roseindia.net/java/java-conversion/StringToDate.shtml
Split the individual parts of the date into Day, Month and Year. Create a Calendar Object, set each part and from this create a java.sql.Date Object.
Here's some test code
String d = "31";
String m = "06";
String y = "2005";
Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_MONTH, Integer.parseInt(d));
c.set(Calendar.MONTH, Integer.parseInt(m));
c.set(Calendar.YEAR, Integer.parseInt(y));
Date da = new Date(c.getTimeInMillis());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Try this import
import java.text.SimpleDateFormat;
import java.util.Date;
String strFormatDate=v;// Your String Date like dd//mm//yy
SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yy");
Date dt =sdf.parse(strFormatDate);
Regards
Abhijith YS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.