cancel
Showing results for 
Search instead for 
Did you mean: 

Getting time in webdynpro

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi

Thanks for the reply.

Does this return the system time if not which time does this return.

Former Member
0 Kudos

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

former_member182294
Active Contributor
0 Kudos

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