Jump to content









Photo

listener processing

time

  • Please log in to reply
2 replies to this topic

#1 dutchguy69

dutchguy69

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 12 January 2014 - 03:08 PM

Hi there fairly new to java and not heard of groovy until recently when I found about your website.

 

I have defined a listener which is sending either sms or email. Within that I want to use the time that is defined within the context at field. This is seconds since epoch value.

 

Tried a couple of things that did not seem to work so went over to the console to see what is going on

 

Long ds = 1389485672000;
date = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date (ds));
 

Message: OK
Details: '01/12/2014 01:14:32'

 

That is fine. But the actual epoch date = 1389485672

 

Doing it the way I want to do it and as I have found many examples around this in the java area.

 

Long ds = 1389485672*1000;
date = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date (ds));
 

Message: OK
Details: '12/07/1969 22:11:08'

 

Then I'm getting invalid results.

 

Long ds = 138948567*10;

 

Message: OK
Details: 1389485670 <- that's fine

 

The above seems to me like a variable type issue where you get overflow etc. However a long should be able to hold 9223372036854775807. Also at the first line it worked and that is the value that is required true the multiplication which seems to contradict the variable type issue.

 

Can someone explain what I'm doing wrong here as it must be something trivial but I'm not able to spot it right now.



#2 sdeancos

sdeancos

    Master of Puppets

  • Members
  • PipPipPip
  • 102 posts
  • LocationMadrid, Spain.

Posted 13 January 2014 - 09:51 AM

Hi!

 

I think the problem is that Groovy is doing a casting automatically, you can try this:

 

Long ds = 1389485672*1000.0;
date = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date (ds));

 

And then you get:

 

Message: OK
Details: '01/12/2014 01:14:32'

 

 

I hope this can help you.



#3 dutchguy69

dutchguy69

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 13 January 2014 - 05:13 PM

Thanks that did the trick, I now have it properly passed through. I had expected that the Long reference in front of the variable would do that trick. But maybe Groovy is different in this situation.







Also tagged with one or more of these keywords: time

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users