Results 1 to 20 of 26
Thread: Date convertion in java
- 05-14-2008, 11:16 AM #1
Member
- Join Date
- Jan 2008
- Posts
- 83
- Rep Power
- 0
- 05-14-2008, 11:20 AM #2
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....Last edited by sukatoa; 05-14-2008 at 11:23 AM.
freedom exists in the world of ideas
- 05-14-2008, 11:51 AM #3
may be this what you wanted:
or may be this one suits you:Java Code:new Timestamp( new Long(myIntValue).longValue() );
Java Code:new Date( new Long(myIntValue).longValue() );
P.N. Timestamp is in java.sql package :)i am the future
- 05-14-2008, 12:13 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
Java Code:long someLong=1210759966477L; Date anotherDate=new Date(someLong); System.out.println(anotherDate.getDate());
- 05-14-2008, 12:25 PM #5
replacement?
as this is depricated, What is the replacement of this excerpt:
?Java 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
- 05-14-2008, 12:30 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Or dear, you have to use
All those things you can found in javadoc. :)Java Code:Calendar.get(Calendar.DAY_OF_MONTH).
By the I got a quiz on it now ;)
- 05-14-2008, 12:37 PM #7
i don't want this actually,
i am having my own date, how to convert that?Java Code:Calendar.get(Calendar.DAY_OF_MONTH).
i am the future
- 05-14-2008, 12:45 PM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What you mean? Looking to convert an int value to date?
- 05-14-2008, 01:07 PM #9
Member
- Join Date
- Jan 2008
- Posts
- 83
- Rep Power
- 0
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..
- 05-14-2008, 01:42 PM #10
preethi
see post #3
i am the future
- 05-14-2008, 02:14 PM #11
Member
- Join Date
- Jan 2008
- Posts
- 83
- Rep Power
- 0
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 1970Date date = new Date(new Long(12234).longValue());
- 05-14-2008, 06:44 PM #12
date = xml_date_value_as_String;I'll get date value from the xml as string and convert it into date
integer = convert(date) ====> What do you mean?and then to integer
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)?
Ahah?!!and do drawing in applet using that value.
is integer from date changed? or what you are talking about is another integer? Why is it updated? where did it came from?Again,i have to update the new integer value as date in the database.
ok, can you also show that integer?(That would be used to convert into date) and the expected date pattern also....Here where i'm struck up..i don't know how to convert an int value into date..Please help me..freedom exists in the world of ideas
- 05-15-2008, 04:54 AM #13
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
Here is an example. I hope it helps
Java 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)); } }
- 05-15-2008, 05:29 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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. :)
- 05-15-2008, 07:09 AM #15
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
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. =PMind only knows what lies near the heart, it alone sees the depth of the soul.
- 05-15-2008, 07:23 AM #16
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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. :)
- 05-15-2008, 07:31 AM #17
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
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.
- 05-15-2008, 08:44 AM #18
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 05-15-2008, 08:52 AM #19
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
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.
- 05-15-2008, 09:56 AM #20
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Ya, it's much better if she got the point.
Similar Threads
-
java.util.Date vs java.sql.Date
By Jack in forum New To JavaReplies: 5Last Post: 10-28-2010, 02:59 PM -
Creating a Gregorian Calendar using a Date object gives date - 1
By prachi_goliwadekar in forum New To JavaReplies: 1Last Post: 05-08-2008, 08:32 PM -
Difference between current date and anothe date
By vijay balusamy in forum New To JavaReplies: 1Last Post: 04-16-2008, 04:15 PM -
Using java.sql.Date
By Java Tip in forum Java TipReplies: 0Last Post: 02-10-2008, 11:32 AM -
Java Date
By levent in forum Java TutorialReplies: 0Last Post: 08-05-2007, 01:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks