Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

convert database date object in to java string object

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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. ???
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ranjith nelanti
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4179
22
IntelliJ IDE Python Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Does this tiny ad smell okay to you?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic