Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Time related issues

 
Manikandan Parthasarathi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am sending a message to jms.queue.
I am reteriving the time from the server.
But its not the actual time. when ever i restart it shows oo.oo.oo
i want the time to be actual system time

i am using EJB3.0 and JBoss 4.2.2
how i can set the regional time?
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you retrieving the time?
 
Manikandan Parthasarathi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting the time by this msg.getJMSTimestamp(). It returns a long which is a milliseconds. i conver that milliseconds into actual time.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the value of the time 0 before or after you convert it?
 
Manikandan Parthasarathi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't get you...
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I'll rephrase the question.

1.) What is the value after you call msg.getJMSTimestamp()
2.) What is the value after you convert that into actual time?
 
Manikandan Parthasarathi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting the following value 1221719820863, and i am not getting the same value every time.

i am using following code to convert it into time format
public String convert(long time) {
int milliseconds = (int) (time % 1000);
int seconds = (int) ((time / 1000) % 60);
int minutes = (int) ((time / 60000) % 60);
int hours = (int) ((time / 3600000) % 24);
String millisecondsStr = ((milliseconds < 10) ? "00"
: ((milliseconds < 100)
? "0" : "")) + milliseconds;
String secondsStr = ((seconds < 10) ? "0" : "") + seconds;
String minutesStr = ((minutes < 10) ? "0" : "") + minutes;
String hoursStr = ((hours < 10) ? "0" : "") + hours;

return new String(hoursStr + ":" + minutesStr + ":" + secondsStr + "." +
millisecondsStr);
}


but i want server time to be synchronized with the regional time
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The given long converted into actual time is "08:37:00.863"

[ September 18, 2008: Message edited by: Rene Larsen ]
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would work with Rene's suggested code (no need to write your own conversion when Java has the API to do it for you)! You can also then look at Calendar and Locale classes in order to get things in the correct timezone etc.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic