Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-14-2008, 01:16 PM
Member
 
Join Date: Jan 2008
Posts: 83
Preethi is on a distinguished road
Date convertion in java
Is it possible to convert integer into datetime?Can anyone say me how to convert from integer to date in java
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-14-2008, 01:20 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Where did you get that integer?

All i know is a long type value that represents date & time.
and can be use as a reference for representing date and time in Calendar, GregorianCalendar, Date,DateFormat and SimpleDateFormat classes....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by sukatoa : 05-14-2008 at 01:23 PM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-14-2008, 01:51 PM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 187
rjuyal is on a distinguished road
may be this what you wanted:

Code:
new Timestamp( new Long(myIntValue).longValue() );
or may be this one suits you:

Code:
new Date( new Long(myIntValue).longValue() );

P.N. Timestamp is in java.sql package
__________________
i am the future
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-14-2008, 02:13 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
This is also possible for a long value. But it's not safe. Suns' deprecated it since version 1.1 But still you can use it.

Code:
long someLong=1210759966477L; Date anotherDate=new Date(someLong); System.out.println(anotherDate.getDate());
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-14-2008, 02:25 PM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 187
rjuyal is on a distinguished road
replacement?
as this is depricated, What is the replacement of this excerpt:

Code:
new java.sql.Date ( year, month, date );
?

or where can i find which new methods we should use for the methods which are depricated?
__________________
i am the future
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-14-2008, 02:30 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Or dear, you have to use

Code:
Calendar.get(Calendar.DAY_OF_MONTH).
All those things you can found in javadoc.

By the I got a quiz on it now
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-14-2008, 02:37 PM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 187
rjuyal is on a distinguished road
i don't want this actually,
Code:
Calendar.get(Calendar.DAY_OF_MONTH).
i am having my own date, how to convert that?
__________________
i am the future
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-14-2008, 02:45 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
What you mean? Looking to convert an int value to date?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-14-2008, 03:07 PM
Member
 
Join Date: Jan 2008
Posts: 83
Preethi is on a distinguished road
I'll get date value from the xml as string and convert it into date and then to integer and do drawing in applet using that value.Again,i have to update the new integer value as date in the database.Here where i'm struck up..i don't know how to convert an int value into date..Please help me..
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-14-2008, 03:42 PM
rjuyal's Avatar
Senior Member
 
Join Date: Mar 2008
Location: Delhi, India
Posts: 187
rjuyal is on a distinguished road
preethi
see post #3
__________________
i am the future
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-14-2008, 04:14 PM
Member
 
Join Date: Jan 2008
Posts: 83
Preethi is on a distinguished road
Quote:
Date date = new Date(new Long(12234).longValue());
If i out put the date,its giving the same value for anykind of data as:Thu Jan 01 05:30:12 GMT+05:30 1970
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 05-14-2008, 08:44 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 527
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Quote:
I'll get date value from the xml as string and convert it into date
date = xml_date_value_as_String;

Quote:
and then to integer
integer = convert(date) ====> What do you mean?

im just curious about what's going on in your implementation...
Maybe im out of topic but, could you post an example of

xml date as string?
integer from date(that represents xml date)?

Quote:
and do drawing in applet using that value.
Ahah?!!

Quote:
Again,i have to update the new integer value as date in the database.
is integer from date changed? or what you are talking about is another integer? Why is it updated? where did it came from?

Quote:
Here where i'm struck up..i don't know how to convert an int value into date..Please help me..
ok, can you also show that integer?(That would be used to convert into date) and the expected date pattern also....
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 05-15-2008, 06:54 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 227
Eku is on a distinguished road
Here is an example. I hope it helps
Code:
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); private Date date2; public static void main(String[] args) { Main main = new Main(); main.date(); } public void date(){ int year=2008,month=05,day=15; \\OR you can use \\String year="2008",month="05",day="15"; try { date = format.parse(year+"-"+month+"-"+day); } catch (ParseException e) { e.printStackTrace(); } System.out.println(format.format(date)); } }
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 05-15-2008, 07:29 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Actually you formatted a string in to date. Even you have int values, built a string and formated. Not bad at all.

But in our original post, try to convert an int value to date. What you can do if the date has in that format, where I discussed in post #4.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 05-15-2008, 09:09 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 227
Eku is on a distinguished road
Post #4 is a direct approach from int to date. I tried to do it in my code but my problem is that is my date is stored in DB. It would be a lot of process to convert it to 'long' and compare it to another date. My friend here uses Strings, he converts everything to String before he manipulate it =P

I guess converting any format to date format is in the Programmers perogative.

As you see Preethi, there are lots of ways to do it in Java. You just need to Explore. =P
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 05-15-2008, 09:23 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Ya I know that. All those implementation depends on the application requirements.

Why you worried about that, storing in DB. Your code can do that.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 05-15-2008, 09:31 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 227
Eku is on a distinguished road
Actually, my code will be used to maintain several databases and accepts different input files. Here they are using Oracle as their Back end software. The issue with Oracle is about their date. Since i cant change the original configuration of the company's date, i have to do something. Oracle doesnt accept the format m/d/yyyy. its most likely in mm/dd/yyyy format and they dont accept the '0' value. Like for example 01/02/2008. It will give me an error saying there is a null value. I made correction by creating my own date checker/converter. I hope Oracle do something about that. =P It took me about 2-3days just to fix that Date problem. Is there another easier way to Fix that?
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 05-15-2008, 10:44 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Sorry pal. I don't know much about Oracle. Most of the time I work on with MySql, and haven't found such as scenario before.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #19 (permalink)  
Old 05-15-2008, 10:52 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 227
Eku is on a distinguished road
Thanks. MySql is Flexible in terms of Date data types than Oracle. Im still new to Oracle database, i dont have any proper training in it. Anyways, I think Preethi can now mark this [SOLVED]. =)
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.
Bookmark Post in Technorati
Reply With Quote
  #20 (permalink)  
Old 05-15-2008, 11:56 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Ya, it's much better if she got the point.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes