on 03-18-2008 1:39 PM
Hi
I need help. I need to represent i a string in the following format
Hour minutes second.
How do i get the system time using webdynpro.
Edited by: Armin Reichert on Mar 19, 2008 1:42 PM
Hi
1)first get the ref of Calender object
Calendar calObj = Calendar.getInstance();
2)then get the hour ,min and sec values by using the following methods
int hour = calObj.get(Calendar.HOUR);
int min = calObj.get(Calendar.MINUTE);
int sec = calObj.get(Calendar.SECOND);
3)Finally u can concat like below
String time = hour+ ":" +min +":" +sec;
Thanks
Hazrath
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi...
Use this code.......................................
java.util.Date sysDate = new java.util.Date();
Calendar calObj = Calendar.getInstance();
calObj.setTime(sysDate);
int hour = calObj.get(Calendar.HOUR);
int min = calObj.get(Calendar.MINUTE);
int sec = calObj.get(Calendar.SECOND);
//you can get other fields like DATE, MONTH, WEEK etc..
String time = hour+ ":" min ":" +sec;
You can do the same with java.util.Date object also. But many of the methods are deprecated.
Regards
Santanu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this code
long timeInMillis = System.currentTimeMillis();
Calendar c = Calendar.getInstance();
c.setTimeInMillis(timeInMillis);
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
String formattedDateString = sdf.format(c.getTime());
This code will work
xxxxxxxxxxxxxxxxxxxx
Warm Regards
Shanto Aloor
Edited by: Armin Reichert on Apr 26, 2008 6:42 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
i think it is better to use DateFormat:
Date date = new Date(System.currentTimeMillis());
DateFormat format = new SimpleDateFormat("hh:mm:ss");
System.out.println(format.format(date));
Regards
Markus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Thanks for the reply.
Does this return the system time if not which time does this return.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Date date = new Date(Calendar.getInstance().getTimeInMillis());
Or
Calendar.getInstance().get(Calendar.DATE)
Calendar.getInstance().get(Calendar.MONTH)
Calendar.getInstance().get(Calendar.DAY_OF_YEAR)
Calendar.getInstance().get(Calendar.YEAR)
Calendar.getInstance().get(Calendar.HOUR)
Calendar.getInstance().get(Calendar.MINUTE)
Calendar.getInstance().get(Calendar.SECOND)
Will return you the current date of your system where the wdapp is deployed
Regards
Ayyapparaj
Use this code:
Calendar calObj = Calendar.getInstance();
int hour = calObj.get(Calendar.HOUR);
int min = calObj.get(Calendar.MINUTE);
int sec = calObj.get(Calendar.SECOND);
//you can get other fields like DATE, MONTH, WEEK etc..
String time = hour+ ":" min ":" +sec;
You can do the same with java.util.Date object also. But many of the methods are deprecated.
Regards
Abhilash
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
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.