It's not a secret anymore!*
The moose likes Beginning Java and the fly likes change calendar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

change calendar

mark I thomas
Ranch Hand

Joined: Apr 07, 2008
Posts: 86


What I want to do is: Given a timestamp of Milliseconds (say 12345678L), I want to get a Calendar that is on the same day as "12345678L" but is at 6:00AM. Does this code achieve that ? I think so but want to hear from you.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

mark I thomas wrote:

What I want to do is: Given a timestamp of Milliseconds (say 12345678L), I want to get a Calendar that is on the same day as "12345678L" but is at 6:00AM. Does this code achieve that ? I think so but want to hear from you.


not exactly. What happens when you run this and print out the entire date and time?
mark I thomas
Ranch Hand

Joined: Apr 07, 2008
Posts: 86
It worked fine for me. here is the sample code



The output is:

date = Tue Sep 04 06:00:47 EDT 2012

Since I didn't reset the "Second" so it copied whatever runtime second value over, but it is good enough for proof of concept.

Any problem ?
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

if you say it is good enough, then it is good enough! How could I have a problem with that?
mark I thomas
Ranch Hand

Joined: Apr 07, 2008
Posts: 86
Tim McGuire wrote:if you say it is good enough, then it is good enough! How could I have a problem with that?


Well, Nobody forced you to give idea if you don't have one. If you have, please get to the point so we can understand you.
mark I thomas
Ranch Hand

Joined: Apr 07, 2008
Posts: 86
Thanks Campbell. Still waiting to receive some meaningful response for the question I asked.
Tarun wadhwa
Greenhorn

Joined: Jan 29, 2011
Posts: 14



OUTPUT
jmaster@Jmaster:~/Desktop$ javac Test.java
jmaster@Jmaster:~/Desktop$ java Test
Current time is : Thu Jan 01 08:55:45 IST 1970
Modified time is : Thu Jan 01 06:00:45 IST 1970

Your code was achieving what you desired for such things you first put your efforts, and do google and find the results then if still facing any problem post your queries...
ADVICE : and be cool when you are on java racnh if some one is devoting time to give answer you must value that no one is forced to give answer but if any one is giving and it don't satisfy you don't put a finger on him/her.

"The More you Play With it, The more you will learn ". "Keep Playing"
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8250
    
  23

mark I thomas wrote:Still waiting to receive some meaningful response for the question I asked.

Actually, Tim's response was right on the money; and when you actually did what he suggested, you answered your own question - or doesn't "proof of concept" mean the same thing to you as it does to me.

What more do you need to know?

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
mark I thomas
Ranch Hand

Joined: Apr 07, 2008
Posts: 86
I already tested my code (by the way it was not from any google..). But I didn't feel 100% sure if I can overwrite an existing timeinMillion so I don't know if there is any potential problem -- and that's why I posted the question.

Tim's response started with "Not really..." puzzled me because I didn't know what that "not really.." menas so I was interested in hearing more from that part but unfortunately I didn't get any insight from him.

I thought when someone said "not really..." he must have something interesting in his mind and that's what I expected to hear and discuss with that person.

Tim's second email even confused me more --- It seems he was asking me "If you think there is no problem then why bother asking ?" Well, Most people believe they write the correct code but people still do code review in team, your peers may identify some potential issue that you don't see -- That's exactly why I posted that question.

I think I am very cool.

mark I thomas
Ranch Hand

Joined: Apr 07, 2008
Posts: 86
When I posted my code and question, I said "with a given long timestamp, say 12345678L" this menas "12345678L" is a hypothetic value. In many cases, people post some pseudo code and if you run that it is not going to work. What I expected to discuss is if the idea works. the hypothetic value is too small so you get wrong results as it was on the same day of epoch.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

mark I thomas wrote:I already tested my code (by the way it was not from any google..). But I didn't feel 100% sure if I can overwrite an existing timeinMillion so I don't know if there is any potential problem -- and that's why I posted the question.

Tim's response started with "Not really..." puzzled me because I didn't know what that "not really.." menas so I was interested in hearing more from that part but unfortunately I didn't get any insight from him.

I thought when someone said "not really..." he must have something interesting in his mind and that's what I expected to hear and discuss with that person.

Tim's second email even confused me more --- It seems he was asking me "If you think there is no problem then why bother asking ?" Well, Most people believe they write the correct code but people still do code review in team, your peers may identify some potential issue that you don't see -- That's exactly why I posted that question.

I think I am very cool.


You are cooler than the other side of the pillow.

when you asked " I want to get a Calendar that is on the same day as "12345678L" but is at 6:00AM. Does this code achieve that ? "

I said "not exactly" because I wanted you to see that what you thought was 6:00 was actually 6:00:45. For my alarm clock in the morning, then this is good enough. For the mars lander, maybe not.

When you said the code worked for you anyway, it became funny because I had identified a potential issue but the requirements began shifting under us.
mark I thomas
Ranch Hand

Joined: Apr 07, 2008
Posts: 86
Tim McGuire wrote:
mark I thomas wrote:I already tested my code (by the way it was not from any google..). But I didn't feel 100% sure if I can overwrite an existing timeinMillion so I don't know if there is any potential problem -- and that's why I posted the question.

Tim's response started with "Not really..." puzzled me because I didn't know what that "not really.." menas so I was interested in hearing more from that part but unfortunately I didn't get any insight from him.

I thought when someone said "not really..." he must have something interesting in his mind and that's what I expected to hear and discuss with that person.

Tim's second email even confused me more --- It seems he was asking me "If you think there is no problem then why bother asking ?" Well, Most people believe they write the correct code but people still do code review in team, your peers may identify some potential issue that you don't see -- That's exactly why I posted that question.

I think I am very cool.


You are cooler than the other side of the pillow.

when you asked " I want to get a Calendar that is on the same day as "12345678L" but is at 6:00AM. Does this code achieve that ? "

I said "not exactly" because I wanted you to see that what you thought was 6:00 was actually 6:00:45. For my alarm clock in the morning, then this is good enough. For the mars lander, maybe not.

When you said the code worked for you anyway, it became funny because I had identified a potential issue but the requirements began shifting under us.



You should learn to understand when people say "with a given long timestamp, say 12345678L", that "say 12345678L" means "12345678L" is a hypothetic value. Just like I say "with a given city name, say ABCDE"... I will feel sorry for you if you really google map that city "ABCDE" but I still appreciate your effort though. --<End of Story>
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8250
    
  23

mark I thomas wrote:You should learn to understand...

Guys, I think you've already been asked once to pipe down. I think the question has been asked and answered.

Mark, unless you feel there is any more life in this thread, I suggest you close it (mark it as 'Resolved').

Winston

mark I thomas
Ranch Hand

Joined: Apr 07, 2008
Posts: 86
Tim McGuire wrote:
mark I thomas wrote:I already tested my code (by the way it was not from any google..). But I didn't feel 100% sure if I can overwrite an existing timeinMillion so I don't know if there is any potential problem -- and that's why I posted the question.

Tim's response started with "Not really..." puzzled me because I didn't know what that "not really.." menas so I was interested in hearing more from that part but unfortunately I didn't get any insight from him.

I thought when someone said "not really..." he must have something interesting in his mind and that's what I expected to hear and discuss with that person.

Tim's second email even confused me more --- It seems he was asking me "If you think there is no problem then why bother asking ?" Well, Most people believe they write the correct code but people still do code review in team, your peers may identify some potential issue that you don't see -- That's exactly why I posted that question.

I think I am very cool.


You are cooler than the other side of the pillow.

when you asked " I want to get a Calendar that is on the same day as "12345678L" but is at 6:00AM. Does this code achieve that ? "

I said "not exactly" because I wanted you to see that what you thought was 6:00 was actually 6:00:45. For my alarm clock in the morning, then this is good enough. For the mars lander, maybe not.

When you said the code worked for you anyway, it became funny because I had identified a potential issue but the requirements began shifting under us.



Technically if this was your thought you have some problem in understanding my question. I set hour and min so it prints as 6:00 AM -- It does not tell you what is the second because I didn't mention what would be the second I expect. You expected the second to be "0" but that's not what I said in my original question. So when you saw your real time second on your computer got printed out you thought there was some problem. This is like --- I said it it should print as Jan 1st, 2012 but I didn't say anything the hour of clock, somehow you assumed it should be 12AM and when you got a different hour from your clock you interpreted as something was wrong.

No matter if it is 6:00:45 or 6:00:43 or 6:00:23, they are ALL 6:00AM cosidering the hour and minute...
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8250
    
  23

I think this has now gone off-topic. Locking.

Winston
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: change calendar