aspose file tools*
The moose likes Java in General and the fly likes convert database date object in to java string object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "convert database date object in to java string object" Watch "convert database date object in to java string object" New topic
Author

convert database date object in to java string object

ranjith nelanti
Greenhorn

Joined: Sep 25, 2012
Posts: 3
Hi,
the date value is stored as "1344449314086" in database. that means this number represents some date.
how to convert this date in to actual date in java. is this stored in UTF-8 ???

is there any sql query or java code to convert this date. ???
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4180
    
  21

ranjith nelanti wrote:Hi,
the date value is stored as "1344449314086" in database. that means this number represents some date.
how to convert this date in to actual date in java. is this stored in UTF-8 ???

That isn't something we can answer. You should go to whoever/whatever put that information into the database and ask them how it gets stored. It could be a simple offset from a fixed point in time.

is there any sql query or java code to convert this date. ???


ResultSet#getDate(String columnName) or one of its sister-methods. Assuming the value is in the correct format.


Steve
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

Welcome to the Ranch.

Java, and other software, stores timestamps as a number of milliseconds since 01-01-1970, 00:00:00 UTC. The number you have looks like such a timestamp. You can simply pass that number to the constructor of java.util.Date, and then you'll get a Date object that represents that date (it seems to be 08-08-2012, 20:08:34 in my local timezone).

This does not have anything to do with UTF-8 or any other character encoding.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
ranjith nelanti
Greenhorn

Joined: Sep 25, 2012
Posts: 3
Jesper de Jong wrote:Welcome to the Ranch.

Java, and other software, stores timestamps as a number of milliseconds since 01-01-1970, 00:00:00 UTC. The number you have looks like such a timestamp. You can simply pass that number to the constructor of java.util.Date, and then you'll get a Date object that represents that date (it seems to be 08-08-2012, 20:08:34 in my local timezone).

This does not have anything to do with UTF-8 or any other character encoding.


thanks for your reply. i already tried this, but if i pass this number as "Long", i am getting out of range exception, or if i pass it as a string, i am getting "java.lang.IllegalArgumentException"...can you please tell me how did you do this.

Date date = new Date(1344449314086); this is not working in my case ?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Try 1344449314086L. An integer constant without a qualifier is an int. To make the expression be of type long, you have to add an L at the end. Since 1344449314086 is too big for an int, it fails without the L. (It won't automatically assume you mean it to be a long. You have to tell it.)
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4180
    
  21

ranjith nelanti wrote:Date date = new Date(1344449314086); this is not working in my case ?

That is using an int, not a long, so you are running past the maximum value for int. You need to use a long, so you should add L to the end of the number:
ranjith nelanti
Greenhorn

Joined: Sep 25, 2012
Posts: 3
Steve Luke wrote:
ranjith nelanti wrote:Date date = new Date(1344449314086); this is not working in my case ?

That is using an int, not a long, so you are running past the maximum value for int. You need to use a long, so you should add L to the end of the number:

great.....worked like a charm..i have been working on this since morning.....glad to you.
 
Don't get me started about those stupid light bulbs.
 
subject: convert database date object in to java string object