• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange problem in date calculation (IS IT BUG!!!)

 
Arshad Ali
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am surprise to see it .



the output is Sun Mar 08 01:30:00 PST 2009 , but when i try this



the output is Sun Mar 08 03:00:00 PDT 2009

WHY this is happening when i am adding only 30 minute .
I need help. It's urgent

Regards
Arshad
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not adding anything, you're setting something. Maybe you meant to do something like
cal.set(Calendar.SECOND, cal.get(Calendar.SECOND) + 1800)


[ UD: Edited to reflect the fact that 1800 seconds is not actually 3 hours, but 30 minutes. What was I smoking? ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not adding time to your Calendar, you are setting the second property to be 1800 seconds. If you want to add time use the add method. (see the JavaDocs)
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its working on my system, My local is India, and its showing in IST format.

When I set SECONDS field by 1800, it shows

Sun Mar 08 15:30:00 IST 2009

The problem may be the 24 hour clock settings
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I seem to be suffering from foot-in-the-mouth disease. But anyways here it goes.
It works fine for me.


Sun Mar 08 09:30:00 GMT 2009
Sun Mar 08 10:00:00 GMT 2009


Effective 2007, the local time changes from PST to PDT at 02:00 LST to 03:00 LDT on the second Sunday in March and returns at 02:00 LDT to 01:00 LST on the first Sunday in November, except in Mexico, where the previous dates are still in effect.


In your example, 8th March is the second sunday, so adding 30 min makes it 2:00 PST which is actually 3:00 PDT due to daylight offset. If you notice your output, it changes from PST to PDT.

And Ulf, 1800 seconds is 30 min.
 
Arshad Ali
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is not working
take this example

i set the time Sunday, March 08, 2009 1:00:00 AM and add 1800 seconds it gave me
Sun Mar 08 01:30:00 PST 2009 , but when i set date to Sunday, March 08, 2009 1:30:00 AM
and add 1800 seconds it gave me Sun Mar 08 03:00:00 PDT 2009 . i need help really.

 
Arshad Ali
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so wat is the solution my friend
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arshad,

I think my post explains your output. The solution will depend on what you want the output to be.
If you let it be, it will be in PDT. If you dont want it so, You probably should do some formatting youself.

Otherwise, a simple message could be passed to the user alerting him about the Time change.
 
Arshad Ali
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
give me solution in proper code my friend
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
give me solution in proper code my friend


Um, Like i said, the solution would depend on what you want. And you should probably rephrase your post before CR or the other bartenders tell you to do so.
 
Arshad Ali
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i try
 
Arshad Ali
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried this and other thing too but no result



any help
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of the JDK are you running this in?

Also, why are you using the deprecated three letter timezone labels?
 
Arshad Ali
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.6 update 10 so what shall i use
 
Steve Fahlbusch
Bartender
Posts: 605
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just what is it that you are expecting.

As discussed by Arshad, this is working as expected (at least for us).

Please elicitate what you are expecting and what you want as a final result.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15448
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arshad Ali wrote:i tried this and other thing too but no result

What exactly does "no result" mean? What did you expect to get, and what did you really get - and what's exactly the difference between what you expected and what you really got?
 
Arshad Ali
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve, actually i am using long date in date calculation and passing to mysql DB but i also have to display it properly.
have you any idea?
 
Steve Fahlbusch
Bartender
Posts: 605
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please be specific and let us know what you mean by properly?

thanks.

in my opinion, how it is displayed in your original posting is proper.

-steve
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arshad Ali,

People here don't understand what you think is wrong. Simply stating "the output is wrong" doesn't help anyone. You have to tell us EXACTLY what output you are seeing, AS WELL AS what output you EXPECT to see.

Without BOTH those pieces of information, NOBODY CAN HELP YOU.
 
Arshad Ali
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, i am using long numeric date in application and performing calculation. now i want to convert date fron PDT to PST format but it is not working.

Regards,
Arshad
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will repeat:

What is the output you see, and what output do you expect to see? Why is this wrong?
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you want to see

Sun Mar 08 02:00:00 PST 2009

instead of

Sun Mar 08 03:00:00 PDT 2009

That is, you do not want to take the daylight offset into account. Am i right?
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arshad Ali wrote:ok, i am using long numeric date in application and performing calculation. now i want to convert date fron PDT to PST format but it is not working.

Regards,
Arshad


If PST stands for what I think it does (Pacific Standard Time) then PDT would be Pacific Daylight Time, which is converting the time for the Daylight Savings Time adjustment. If your going to be doing addition on times that cross that 2 AM time period that Sunday you are going to hit the problem. If you convert PDT to PST (which I'm not sure can be done with the date being the DST transition) then the time your program outputs will not be the correct time. If you are really trying for it, you could write an if statement so if the dates are in between the start of DST and the end of DST, subtract one hour from the time. Other than that, however, I don't know that you can force the program to run PST instead of PDT, since it seems like PST is the same as PDT when PDT is in effect.

If that made no sense to anyone else please say so and I will try to explain more clearly.
 
Arshad Ali
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the problem is i try to convert from PDT to PST but no result , so i think i need to check if date is in daylight time then perform calculation. let's see.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic