• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hard time with java.sql.date

 
Giselle Dazzi
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beginner's question:
I want to create a Date object using the constructor:

Date(long date)
Constructs a Date object using the given milliseconds time value.

but Im having a very hard time figuring out how to find out the current date in miliseconds...
I tried creating a Calendar object, using

But still there is no method that gives me a value in miliseconds...
thx in advance,
 
Benny Tang
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
After the instantiation of the Calendar instance, you can obtain a Date instance by invoking the method getTime() in the class Calendar. Hopes this can help you.
Benny Tang
 
deepak yadav
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am replying on the basis of the subject, the contents of the post didn't revealed that the actual problem is with java.sql.Date
java.sql.Date doesn't have a time component, so there is not much point in making an instance of that using a time precision of miliseconds
-deepak
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gizelle --
Benny's statement is correct, but if all you want is the current time in milliseconds, you can get it using the static method System.currentTimeMillis().
Deepak --
Have a look at the constructor java.sql.Date(long).
 
deepak yadav
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hill,
java.sql.Date does have the time component but it is better not to use it because it has been deprecated long ago. Also i had problems using java.sql.Date in CMP (WLS 8.1). The time component wasn't appearing in the database(Oracle 8i), but when i used java.util.Date or java.sql.Timestamp it worked fine.
-------------------------------------------
This is from 1.3.1 javadocs
public int getHours()
Deprecated.
This method is deprecated and should not be used because SQL Date values do not have a time component.
-------------------------------------------
-deepak
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Giselle Dazzi:
Beginner's question:
I want to create a Date object using the constructor:



double check to make sure that the getTime() method preserves the "brasilia" time zone or if it reverts back to the default timezone of the computer.
Jamie
 
Giselle Dazzi
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help everybody ! It has been crazy with this project I have to finish, I ended up not thanking you sooner.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic