• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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? ]
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so wat is the solution my friend
 
Sridhar Santhanakrishnan
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok i try
 
Arshad Ali
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried this and other thing too but no result



any help
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.6 update 10 so what shall i use
 
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic